将库添加到现有项目netbeans [英] Add library to existing project netbeans

查看:215
本文介绍了将库添加到现有项目netbeans的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我公司的(另一个人)现有项目中添加扩展程序。现在我想导入一个现有的库,如boost。我使用netbeans调试现有项目。现在为了将库导入到netbeans中,通常需要执行以下两个步骤:

I am adding extensions to an (another persons) existing project at my company. Now I want to import an existing library like boost to it. I am using netbeans for debugging the existing project. Now in order to import a library into netbeans usually 2 steps are followed:


  1. 包含目录

  2. 链接器 - >添加库。

然而,当我右键单击我现有的项目时,Linker-> Add Library的选项不会出现。 (虽然我已经包含目录,因为该选项是有)。

However when I right click on my existing project the option of Linker->Add Library is not appearing. (Though I have included the directories as that option is there).

有人可以指导我如何通过链接器添加库到我现有的项目?我的项目是在C + +

Can someone please guide me as to how should I add the library through linker to my existing project? My project is in C++

推荐答案

假设你使用unix / linux变体:

Assuming you are using unix/linux variants:

头文件和库链接的目录是两个不同的东西。 Include目录将具有所需的头,但编译之后,也可能需要驻留在库(* .a,* .so,etc ...)中的实际编译代码。

Directories for headers and library linking are two different things. Include directories will have the headers needed, but after compilation the actual compiled code that resides in the libraries (*.a, *.so, etc...) might also be required.

例如,如果您使用的是pthread,除了需要包含的标题,还需要libpthread。

For example, if you are using pthreads, apart from the headers which you need to include, you also need libpthread.

链接时,用于链接pthread的标志ie:-lpthread
您可以使用find或locate在unix系统上进行搜索以查找库。在我的例子中,它在

When linking, you need to provide the flag for linking with pthread i.e: -lpthread You can search using find or locate on a unix system to find the libraries. In my case, its in


/usr/lib/libpthread.so

/usr/lib/libpthread.so

因此,


gcc myfile.c -lpthread -o myfile

gcc myfile.c -lpthread -o myfile

将myfile.c与pthread库链接

Will link myfile.c with pthread library

然而,


gcc -L / usr / local / lib /

gcc -L/usr/local/lib/

告诉gcc / usr / local / lib来搜索库(而不是标题!)。

Tells gcc to look under /usr/local/lib to search for the library (not the header!).

告诉netbeans头标在哪里,是不够的,链接错误。告诉netbeans库在哪里,可能就足够了,因为它可能使用适当的标志。如果这也失败,那么你必须指定库标志和路径。

Telling netbeans where the headers are, isn't enough, it will probably give you linking errors. Telling netbeans where the libraries are, may be enough, as it might use the proper flags. If that also fails, then you have to specify both the library flags and the path.

或者,你可以使用像cmake,make等工具自动化这个过程,提供更多的控制IMO。

Alternatively, you may use tools like cmake, make, etc which automate this process and provide a bit more control IMO.

查看链接1
查看链接2

这篇关于将库添加到现有项目netbeans的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆