Xcode:如何链接预编译的 c++图书馆
新手问题:
我有一个 C++ 中的小测试类(TestLibMain.cpp),并将其编译为“libTestLib.dylib”,该类位于包含 TestLibMain.h 文件的目录的子目录“debug”中。
如何使用 Xcode 项目中的 dylib?我在代码中导入了 TestLibMain.h 并在构建设置中设置了标头搜索路径。这很好用。但现在链接器告诉我他找不到dylib(也找不到他可以自己编译的“TestLibMain.cpp”文件......)。在 Ecplise/CDT 中创建的 dylib 有一个不同的名称:“libTestLib.dylib”。在 Xcode 中设置“库搜索路径”没有帮助......
这是我的错误消息:
Undefined symbols for architecture i386:
"TestLibMain::TestLibMain()", referenced from:
-[tbViewController viewWillAppear:] in tbViewController.o
"TestLibMain::getNumber()", referenced from:
-[tbViewController viewWillAppear:] in tbViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
问题:
- 是否可以在 Xcode 中链接为 i386 创建的 dylib 文件?我想在 Xcode 项目中使用从 Eclipse 中的项目编译的库(我想在 Android NDK 中重用...)
- 如何让 Xcode 找到 dylib 文件?
- dylib 文件实际上是链接的正确文件吗?没有eclipse创建的.a文件,而是.d和.o文件?
Newbie-Problem:
I have a small test-class (TestLibMain.cpp) in c++ an compiled it to a "libTestLib.dylib" which is located in a subdirectory "debug" of the directory containing the TestLibMain.h-file.
How can I use the dylib from my Xcode-project? I imported the TestLibMain.h in my code and set the Header-search path in build settings. This works fine. But now the linker tells me that he can't find the dylib (nor the "TestLibMain.cpp" file which he could compile himself...). The dylib was created in Ecplise/CDT has a different name: "libTestLib.dylib". Setting the "Library search paths" in Xcode doesn't help....
This my error message:
Undefined symbols for architecture i386:
"TestLibMain::TestLibMain()", referenced from:
-[tbViewController viewWillAppear:] in tbViewController.o
"TestLibMain::getNumber()", referenced from:
-[tbViewController viewWillAppear:] in tbViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Questions:
- Is it possible to link a dylib-file created for i386 in Xcode? I want to use in a Xcode- project compiled libs from a project in Eclipse (which I want to reuse in Android NDK...)
- How can I make Xcode find the dylib-file?
- Is actually the dylib file the right file to link? There has no .a file created by eclipse, but a .d and a .o file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1.如果您在 iOS 项目中使用 dylib - 这是不可能的,因为 Apple 不允许使用自定义动态库。您也不能使用使用 NDK 构建的库,即使它们适用于相同的架构,因为它们具有不同的二进制格式(Mac OS 和 iOS 使用 Mach-O,Android 使用 ELF)。
2.转到您的目标首选项->构建阶段->按“+”->添加其他
3.dylib 是正确的文件,除非它不是 iOS 项目。
1.If you are using the dylib for the iOS project - it is not possible, cause it is not permitted by Apple to use custom dynamic libraries. You also can't use libraries built using NDK even if they are for the same architecture, cause they have different binary format (Mac OS and iOS use Mach-O and Android uses ELF).
2.Go to your target preferences->Build phases->press '+'->Add other
3.dylib is the right file unless it is not an iOS project.