Linux C++:eclipse CDT 中的外部库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8834883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C++: External library in eclipse CDT
提问by Mr.Cool
Now I am using eclipse CDT for my C/C++ Application, but there is problem when I link my external library, it could not be loaded properly at run time, even through I put the library file near the source file, I gave the library path, and it's name correctly.
现在我正在为我的 C/C++ 应用程序使用 eclipse CDT,但是当我链接我的外部库时出现问题,它无法在运行时正确加载,即使我将库文件放在源文件附近,我给了库路径,它的名字是正确的。
project directory:
项目目录:
- include(.h files)
- source(.cpp. files..)
- lib(libbozorth3.a,LSFMatcher.a)
- 包括(.h 文件)
- 源(.cpp. 文件..)
- 库(libbozorth3.a,LSFMatcher.a)
I want link that static libraries with my application I follow this steps:
我想将静态库与我的应用程序链接我按照以下步骤操作:
- project->properties->general->path and symbols->include directory path,and libraries(bozorth3.a,LSFMatcher.a),and add library path .
- and also i add the same library in linker section also
- project->properties->general->path and symbols->include directory path,and libraries(bozorth3.a,LSFMatcher.a),并添加库路径。
- 而且我也在链接器部分添加了相同的库
When I build the program it displays a error cannot find -lbozorth3.a cannot find -lLSFMatcher.a
当我构建程序时,它显示错误找不到 -lbozorth3.a 找不到 -lLSFMatcher.a
So I need the correct steps to add the external library to c/c++ application.
所以我需要正确的步骤来将外部库添加到 c/c++ 应用程序。
采纳答案by FSaccilotto
I normally configure
我一般配置
- the library
- the library search path (Needed for compiliation)
- the runtime search path (-rpath Linker option)
- 图书馆
- 库搜索路径(编译需要)
- 运行时搜索路径(-rpath 链接器选项)
(see images below and exchange the path in the Linker flags to that one you used in the library search path)
(参见下图,并将链接器标志中的路径交换为您在库搜索路径中使用的路径)
回答by Rahul Ravi
you should use -Wl,-rpath=${workspace_loc}/Liball
and not -Wl,-rpath,${workspace_loc}/Liball
.
你应该使用-Wl,-rpath=${workspace_loc}/Liball
而不是-Wl,-rpath,${workspace_loc}/Liball
.
Also under library -l option add library like eg. for libgcc.a add only gcc
同样在 library -l 选项下添加库,例如。对于 libgcc.a 只添加 gcc
回答by lopes
You should pay attention to what is in parentheses: Other options (-Xlinker [option]).
您应该注意括号中的内容:其他选项(-Xlinker [option])。
The way to pass options is different. Instead of using:
传递选项的方式不同。而不是使用:
-Wl,-rpath,'${ProjDirPath}/../../system/lib'
You must use:
您必须使用:
-rpath '${ProjDirPath}/../../system/lib'
That is, remove the "-Wl," and replace the second "," by " " (space).
也就是说,删除“-Wl”,并用“”(空格)替换第二个“,”。