简体   繁体   English

将目标 C 库与 C/C++ 代码库链接

[英]Link objective C library with C/ C++ Code base

We have a library with objective-c classes and exposed C APIs to use these classes.我们有一个库,其中包含 objective-c 类和公开的 C API 以使用这些类。 Now on iOS, i would like link it with c code base.现在在 iOS 上,我想将它与 c 代码库链接。 How can i link this library statically with c code base.如何将此库与 c 代码库静态链接。

Please suggest.请建议。

I tried the following and giving the following error:我尝试了以下并给出了以下错误:

$gcc -static cApp.c -L. -lTestLib 
ld: library not found for -lcrt0.o
collect2: ld returned 1 exit status
$

Please help Thanks请帮忙谢谢

The -static flag will prevent any dynamic linking, which in this case breaks the linking against the C runtime library. -static标志将阻止任何动态链接,在这种情况下会破坏与 C 运行时库的链接。 If TestLib is a static library then it should work if you just remove the -static flag.如果 TestLib 是 static 库,那么只要删除-static标志,它应该可以工作。

$gcc cApp.c -L. -lTestLib 

Note that this will try to build a binary for the host operating system.请注意,这将尝试为主机操作系统构建二进制文件。 You may want to set the appropriate SDK and architecture if you build for iOS.如果您为 iOS 构建,您可能需要设置适当的 SDK 和架构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM