[英]Proper Xcode settings
I have Xcode 5.1.1 and am trying to create a project to build my application for the OSX.我有 Xcode 5.1.1 并且正在尝试创建一个项目来为 OSX 构建我的应用程序。
The application is structured as follows:该应用程序的结构如下:
I have a static link library (.a), 2 dynamic link libraries (.dylib), which depends on the static one, 1 dynamic library (.dylib) that depends on those 2 dynamic libraries and the executable binary which uses that 1 dynamic library (.dylib).我有一个静态链接库 (.a),2 个动态链接库 (.dylib),它依赖于静态库,1 个动态库 (.dylib),它依赖于这 2 个动态库和使用那 1 个动态库的可执行二进制文件库(.dylib)。
In the Xcode I changed the output directory by going to "Xcode ->Preferences->Derived Data (Advanced)".在 Xcode 中,我通过转到“Xcode ->Preferences->Derived Data (Advanced)”更改了输出目录。 There I selected "Custom->Relative to Workspace".
在那里我选择了“自定义-> 相对于工作区”。 This way everything will be kept in one place.
这样,所有内容都将保存在一个地方。
Now here is the problem: I'm having difficulties adding ".a" library to one of the ".dylib".现在问题来了:我在将“.a”库添加到“.dylib”之一时遇到了困难。
I selected a target in the upper left corner of the Xcode window in order for the build properties to appear.我在 Xcode 窗口的左上角选择了一个目标,以便显示构建属性。 Then in the "Search" window I typed "other linker flags".
然后在“搜索”窗口中输入“其他链接器标志”。 Then I selected "Other Linker Flags" in the "Build Settings Window" and typed "-ldbinterface.a".
然后我在“构建设置窗口”中选择了“其他链接器标志”并输入了“-ldbinterface.a”。 Trying to compile I got an error: "ld: library not found for -llibdbinterface.a".
尝试编译时出现错误:“ld:未找到 -llibdbinterface.a 的库”。
Next I tried to add the following line: "-L/Users/igorkorot/dbhandler/dbhandler/Build/Products/Debug" to "Other Linker Flags".接下来我尝试添加以下行:“-L/Users/igorkorot/dbhandler/dbhandler/Build/Products/Debug”到“Other Linker Flags”。 But I got exactly the same error.
但我得到了完全相同的错误。
Next I tried to remove those 2 lines and to add just "libdbinterface.a" to "Other Linker Flags".接下来,我尝试删除这两行,并将“libdbinterface.a”添加到“其他链接器标志”。 This time I got: "clang: error: No such file or directory".
这次我得到:“clang:错误:没有这样的文件或目录”。
For the reference, that file does exist:作为参考,该文件确实存在:
Igors-MacBook-Air:Debug igorkorot$ pwd
/Users/igorkorot/dbhandler/dbhandler/Build/Products/Debug
Igors-MacBook-Air:Debug igorkorot$ ls -la
total 384
drwxr-xr-x 3 igorkorot staff 102 Mar 26 18:37 .
drwxr-xr-x@ 3 igorkorot staff 102 Mar 26 18:36 ..
-rw-r--r-- 1 igorkorot staff 193528 Mar 26 18:37 libdbinterface.a
What am I doing wrong?我究竟做错了什么? What is the proper way of adding the static library in my case?
在我的情况下添加静态库的正确方法是什么?
Thank you.谢谢你。
If the filename of the static library is:如果静态库的文件名是:
libdbinterface.a
Then you need to specify it to the -l
linker option by stripping the leading lib
and the file extention ( .a
):然后,您需要通过剥离前导
lib
和文件扩展名 ( .a
) 将其指定给-l
链接器选项:
-ldbinterface
However I see trouble ahead in that I think you might find a duplicate symbol definition (linker error or a runtime issue) as the symbols from the static library will appear in both dynamic libraries.但是,我看到了前面的问题,因为我认为您可能会发现重复的符号定义(链接器错误或运行时问题),因为来自静态库的符号将出现在两个动态库中。
There are two ways of solving that:有两种方法可以解决:
Compile the dynamic libraries with Symbols Hidden By Default set to Yes (under Build Settings > Code Generation ) and only expose the symbols you want to export by annotating the methods using:编译动态库,将Symbols Hidden By Default设置为Yes (在Build Settings > Code Generation 下),并仅通过使用以下方法注释方法来公开要导出的符号:
__attribute__ ((visibility ("default")))
which you would normal do with a macro:您通常会使用宏执行以下操作:
#define EXPORT __attribute__ ((visibility ("default")))
and in the function/variable declarations only use this form:并且在函数/变量声明中只使用这种形式:
extern EXPORT void aFunction(int someParam);
Note: You don't need to do this for Objective-C classes, but you might need to for C++ (I cannot remember).注意:您不需要为 Objective-C 类执行此操作,但您可能需要为 C++ 执行此操作(我不记得了)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.