简体   繁体   English

将库添加到现有项目netbeans

[英]Add library to existing project 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. 现在,我想导入一个像boost这样的现有库。 I am using netbeans for debugging the existing project. 我正在使用netbeans调试现有项目。 Now in order to import a library into netbeans usually 2 steps are followed: 现在,为了将库导入到netbeans中,通常遵循以下两个步骤:

  1. Include directories 包含目录
  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). (尽管我已经将目录包括在内,因为该选项在那里)。

Can someone please guide me as to how should I add the library through linker to my existing project? 有人可以指导我如何通过链接器将库添加到现有项目吗? My project is in C++ 我的项目是C ++

Assuming you are using unix/linux variants: 假设您正在使用unix / linux变体:

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. 包含目录将具有所需的头,但是在编译后,可能需要驻留在库中的实际已编译代码(* .a,*。so等)。

For example, if you are using pthreads, apart from the headers which you need to include, you also need libpthread. 例如,如果您使用的是pthreads,则除了需要包含的标头外,还需要libpthread。

When linking, you need to provide the flag for linking with pthread ie: -lpthread You can search using find or locate on a unix system to find the libraries. 链接时,需要提供用于与pthread链接的标志,即:-lpthread可以使用find或在unix系统上查找来查找库。 In my case, its in 就我而言,

/usr/lib/libpthread.so /usr/lib/libpthread.so

Therefore, 因此,

gcc myfile.c -lpthread -o myfile gcc myfile.c -lpthread -o myfile

Will link myfile.c with pthread library 将myfile.c与pthread库链接

Whereas, 鉴于,

gcc -L/usr/local/lib/ gcc -L / usr / local / lib /

Tells gcc to look under /usr/local/lib to search for the library (not the header!). 告诉gcc在/ usr / local / lib下查找库(不是标题!)。

Telling netbeans where the headers are, isn't enough, it will probably give you linking errors. 告诉netbeans标头在哪里还不够,它可能会给您链接错误。 Telling netbeans where the libraries are, may be enough, as it might use the proper flags. 告诉netbeans库在哪里就足够了,因为它可能使用适当的标志。 If that also fails, then you have to specify both the library flags and the path. 如果仍然失败,则必须同时指定库标志和路径。

Alternatively, you may use tools like cmake, make, etc which automate this process and provide a bit more control IMO. 另外,您可以使用cmake,make等工具来自动执行此过程,并提供更多的IMO控制。

See Link 1 See link 2 参见链接1 参见链接2

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

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