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

2023-08-27C/C++开发问题
2

本文介绍了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.cppSign.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++ 静态库项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&amp;()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6