创建和使用简单的.dylib [英] Creating and Using a Simple .dylib
问题描述
在Xcode中创建和使用.dylib的最基本的方法是什么?
这里是我到目前为止:
文件:MyLib.h
#include< string&
命名空间MyLib
{
void SayHello(std :: string Name);
}
文件:MyLib.cpp
#include< string>
#include< iostream>
#includeMyLib.h
void MyLib :: SayHello(std :: string Name)
{
std :: cout< < Hello,<<名称<< !;
}
我将项目编译为动态库,它与其他项目?我尝试这样的:
文件:MyLibTester.cpp
#includelibMyLib.dylib
int main()
{
MyLib :: SayHello(world);
return 0;
}
但是这给了我400多个错误$ c> Stray \123 in program 。使用< libMyLib.dylib>
给我一个 / code>错误。
您不包括库文件, / p>
写
#includeMyLib.h
然后你必须告诉编译器你的程序链接到dylib文件如果你使用Xcode,你可以直接拖动dylib文件到你的项目。 / p>
What's the most basic way to create and use a .dylib in Xcode?
Here's what I have so far:
File: MyLib.h
#include <string>
namespace MyLib
{
void SayHello(std::string Name);
}
File: MyLib.cpp
#include <string>
#include <iostream>
#include "MyLib.h"
void MyLib::SayHello(std::string Name)
{
std::cout << "Hello, " << Name << "!";
}
I got the project to compile as a dynamic library, but how do I use it with other projects? I tried something like this:
File: MyLibTester.cpp
#include "libMyLib.dylib"
int main()
{
MyLib::SayHello("world");
return 0;
}
But that gave me over 400 errors (mostly along the lines of Stray \123 in program
. Using <libMyLib.dylib>
gave me a file not found
error.
You don't include the library file, but the header (.h)
So write
#include "MyLib.h"
You then have to tell the compiler for your program to link against the dylib file. If you are using Xcode you can simply drag the dylib file into your project.
这篇关于创建和使用简单的.dylib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!