Netbeans: how to include other c++ static library project?(Netbeans:如何包含其他 C++ 静态库项目?)
问题描述
我对 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++ 静态库项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Netbeans:如何包含其他 C++ 静态库项目?
基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- CString 到 char* 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
