问题描述
我对 C++ 真的很陌生,现在正在使用 Netbeans.
I am really new to c++ and am using Netbeans for now.
我设法创建了一个包含工作类 Sign
的 Sign.h 和 Sign.cpp.我将这些添加到控制台项目中,效果很好:
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:
#include <iostream>
#include <ostream>
#include "Sign.h"
int main()
{
Sign sign = Sign::parse("b");
std::cout << sign.toString() << " " << sign.getValue() <<"
";
}
但是,我想创建一个包含 Sign
类的静态库,所以我创建了一个静态库并添加了 Sign.cpp
和 Sign.h
到它.现在的问题是,我似乎无法将 Sign 类包含在主控制台程序中.
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.
我在 Options => 中添加了库构建 =>链接器 =>库
,并将其添加到所需项目
.但是我不能使用 #include
或 #include
.
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>
.
我在这里遗漏了什么?
推荐答案
您需要一个库中的两个文件.库文件(Windows 上的 .lib,Linux 上的 .a)和包含文件(.h 文件).
You need two files from a library. The library file (.lib on windows, .a on linux) and the include file (.h files).
选项 => 构建 => 链接器 => 库仅用于库文件.您还需要在 File => Project Properties => 下设置包含的路径构建 => C++ 编译器 => 通用 => 包含目录
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
这篇关于Netbeans:如何包含其他 C++ 静态库项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!