将库添加到现有项目netbeans

编程入门 行业动态 更新时间:2024-10-26 15:13:02
本文介绍了将库添加到现有项目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:

  • 包含目录
  • 链接器 - >添加库。
  • 然而,当我右键单击我现有的项目时,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

    本文发布于:2023-11-03 12:21:00,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1555120.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:项目   netbeans

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!