简体   繁体   English

Netbeans:如何包含其他c ++静态库项目?

[英]Netbeans: how to include other c++ static library project?

I am really new to c++ and am using Netbeans for now. 我对c ++很陌生,现在正在使用Netbeans。

I managed to create a Sign.h and Sign.cpp containing a working class Sign . 我设法创建一个包含工作类Sign的Sign.h和Sign.cpp。 I added these to a Console Project and it works great: 我将这些添加到控制台项目中并且效果很好:

  #include <iostream>
  #include <ostream>
  #include "Sign.h"

  int main()
  {
      Sign sign = Sign::parse("b");
      std::cout << sign.toString() << " " << sign.getValue() <<"\n";
  }

However, I want to create a static library containing the Sign class, so I created a static library and added Sign.cpp and Sign.h to it. 但是,我想创建一个包含Sign类的静态库,所以我创建了一个静态库并向其添加了Sign.cppSign.h The problem now is, that I can't seem to get my Sign class to be included in the main console program. 现在的问题是,我似乎无法将我的Sign类包含在主控制台程序中。

I added the library in Options => Build => Linker => Libraries , and added it to the required projects . 我在Options => Build => Linker => Libraries添加了Options => Build => Linker => Libraries ,并将其添加到required projects However I can't use #include <Sign> or #include <Sign.h> . 但是我不能使用#include <Sign>#include <Sign.h>

What am I missing here? 我在这里错过了什么?

You need two files from a library. 您需要库中的两个文件。 The library file (.lib on windows, .a on linux) and the include file (.h files). 库文件(Windows上的.lib,Linux上的.a)和包含文件(.h文件)。

The Options => Build => Linker => Libraries is only for the library file. Options => Build => Linker => Libraries仅适用于库文件。 You also need to set the path for the includes under File => Project Properties => Build => C++ Compiler => General => Include Directories 您还需要在File => Project Properties => Build => C ++ Compiler => General => Include Directories下设置包含的路径

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

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