Netbeans:如何包含其他 C++ 静态库项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3264294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Netbeans: how to include other c++ static library project?
提问by Peterdk
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
.
I added these to a Console Project and it works great:
我设法创建了一个包含工人阶级的 Sign.h 和 Sign.cpp Sign
。我将这些添加到控制台项目中,效果很好:
#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. The problem now is, that I can't seem to get my Sign class to be included in the main console program.
不过,我想创建一个包含静态库Sign
类,所以我创建了一个静态库和添加Sign.cpp
,并Sign.h
给它。现在的问题是,我似乎无法将我的 Sign 类包含在主控制台程序中。
I added the library in Options => Build => Linker => Libraries
, and added it to the required projects
. However I can't use #include <Sign>
or #include <Sign.h>
.
我在 中添加了库Options => Build => Linker => Libraries
,并将其添加到required projects
. 但是我不能使用#include <Sign>
or #include <Sign.h>
。
What am I missing here?
我在这里缺少什么?
回答by Victor Marzo
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. You also need to set the path for the includes under File => Project Properties => Build => C++ Compiler => General => Include Directories
Options => Build => Linker => Libraries 仅用于库文件。您还需要在 File => Project Properties => Build => C++ Compiler => General => Include Directories 下设置包含的路径