简体   繁体   English

C ++:eclipse CDT中的外部库

[英]C++: External library in eclipse CDT

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. 现在我使用eclipse CDT作为我的C / C ++应用程序,但是当我链接我的外部库时出现问题,它无法在运行时正确加载,即使我把库文件放在源文件附近,我给了库路径,它的名称正确。

project directory: 项目目录:

  1. include(.h files) 包括(.h文件)
  2. source(.cpp. files..) 来源(.cpp。文件..)
  3. lib(libbozorth3.a,LSFMatcher.a) LIB(libbozorth3.a,LSFMatcher.a)

I want link that static libraries with my application I follow this steps: 我希望链接静态库与我的应用程序我按照以下步骤:

  1. project->properties->general->path and symbols->include directory path,and libraries(bozorth3.a,LSFMatcher.a),and add library path . project-> properties-> general-> path和symbols-> include目录路径和库(bozorth3.a,LSFMatcher.a),并添加库路径。
  2. and also i add the same library in linker section also 我也在链接器部分添加了相同的库

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 ++应用程序。

I normally configure 我通常配置

  1. the library 图书馆
  2. the library search path (Needed for compiliation) 库搜索路径(需要编译)
  3. 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) (请参阅下面的图像并将链接器标记中的路径交换为您在库搜索路径中使用的路径)

图书馆搜索路径运行时搜索路径的链接器选项

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而不是-Wl,-rpath=${workspace_loc}/Liball-Wl,-rpath=${workspace_loc}/Liball -Wl,-rpath,${workspace_loc}/Liball

Also under library -l option add library like eg. 同样在库-l选项下添加库,例如。 for libgcc.a add only gcc 对于libgcc.a只添加gcc

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”,并用“”(空格)替换第二个“,”。

在此输入图像描述

在此输入图像描述

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

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