我有一个自定义库(.a 文件),我想将其添加到 Eclipse 中的 C 项目中。
我尝试将其添加到项目首选项 -> C/C++ 常规 -> 路径和符号 -> 库
中。此位置自动显示在项目首选项 -> C/C++ 构建 -> 设置 -> 工具设置 -> MacOS X C 链接器 -> 库
当我构建项目时,我在构建控制台中收到以下错误:
Building target: TestOfLibrary
Invoking: MacOS X C Linker
gcc -o "TestOfLibrary" ./src/TestOfLibrary.o -l"/Users/me/workspaces/test/libs/mylib.a"
ld: library not found for -l/Users/me/workspaces/test/libs/mylib.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [TestOfLibrary] Error 1
库的路径正确,没有拼写错误,并且文件存在。
可能是什么问题?
最佳答案
@托伯
在 gcc 命令选项上,您可能需要添加库搜索路径标志。假设您正在链接静态库 (mylib.a),以下将是您要运行的命令/标志:
gcc TestOfLibrary.c -L/Users/me/workspaces/test/libs -lmylib
The directories searched include several standard system directories plus any > that you specify with -L.
Normally the files found this way are library files—archive files whose members > are object files.
进一步引用:Options for Linking .
话虽这么说,这是我的 Eclipse 配置,我会用它来进行相应的设置:
C/C++ 构建/设置:http://www.screencast.com/t/vJLsjzGVJ8N
让我知道进展如何。
关于c - 链接器无法在 OSX 上的 Eclipse C 上找到现有库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26110105/