C++ 如何在 Windows 上为 NetBeans 和 gcc 添加库包含路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11621885/
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
How to add a library include path for NetBeans and gcc on Windows?
提问by XP1
How to add a library include path for NetBeans and gcc on Windows?
如何在 Windows 上为 NetBeans 和 gcc 添加库包含路径?
Using:
使用:
- NetBeans 7.1.2
- MinGW (
mingw-get-inst-20120426.exe
) - gcc 4.7.0
- NetBeans 7.1.2
- 明威 (
mingw-get-inst-20120426.exe
) - 海湾合作委员会 4.7.0
回答by XP1
For example, you want to add the directories in C:\Program Files (x86)\Example\1.0\include\
as the include paths.
例如,您希望将目录添加C:\Program Files (x86)\Example\1.0\include\
为包含路径。
First, set up code assistance:
一、设置代码辅助:
- NetBeans > Tools > Options > C/C++ > Code Assistance
- C Compiler > Include Directories:
C:\Program Files (x86)\Example\1.0\include\shared
C:\Program Files (x86)\Example\1.0\include\other
C:\Program Files (x86)\Example\1.0\include
C:\MinGW\lib\gcc\mingw32\4.7.0\include
C:\MinGW\include
C:\MinGW\lib\gcc\mingw32\4.7.0\include-fixed
- ...
- C++ Compiler > Include Directories:
C:\Program Files (x86)\Example\1.0\include\shared
C:\Program Files (x86)\Example\1.0\include\other
C:\Program Files (x86)\Example\1.0\include
C:\MinGW\lib\gcc\mingw32\4.7.0\include\c++
C:\MinGW\lib\gcc\mingw32\4.7.0\include\c++\mingw32
C:\MinGW\lib\gcc\mingw32\4.7.0\include\c++\backward
C:\MinGW\lib\gcc\mingw32\4.7.0\include
C:\MinGW\include
C:\MinGW\lib\gcc\mingw32\4.7.0\include-fixed
- ...
- OK.
- C Compiler > Include Directories:
- NetBeans > 工具 > 选项 > C/C++ > 代码帮助
- C 编译器 > 包含目录:
C:\Program Files (x86)\Example\1.0\include\shared
C:\Program Files (x86)\Example\1.0\include\other
C:\Program Files (x86)\Example\1.0\include
C:\MinGW\lib\gcc\mingw32\4.7.0\include
C:\MinGW\include
C:\MinGW\lib\gcc\mingw32\4.7.0\include-fixed
- ...
- C++ 编译器 > 包含目录:
C:\Program Files (x86)\Example\1.0\include\shared
C:\Program Files (x86)\Example\1.0\include\other
C:\Program Files (x86)\Example\1.0\include
C:\MinGW\lib\gcc\mingw32\4.7.0\include\c++
C:\MinGW\lib\gcc\mingw32\4.7.0\include\c++\mingw32
C:\MinGW\lib\gcc\mingw32\4.7.0\include\c++\backward
C:\MinGW\lib\gcc\mingw32\4.7.0\include
C:\MinGW\include
C:\MinGW\lib\gcc\mingw32\4.7.0\include-fixed
- ...
- 好的。
- C 编译器 > 包含目录:
The C:\MinGW\...
directories are examples only. Do not actually add them. NetBeans should have detected and added the MinGW directories automatically. If not, try resetting the settings:
这些C:\MinGW\...
目录只是示例。不要实际添加它们。NetBeans 应该已经自动检测并添加了 MinGW 目录。如果没有,请尝试重置设置:
- NetBeans > Tools > Options > C/C++
- Code Assistance
- C Compiler > Reset Settings
- C++ Compiler > Reset Settings
- Build Tools
- Restore Defaults
- Code Assistance
- NetBeans > 工具 > 选项 > C/C++
- 代码帮助
- C 编译器 > 重置设置
- C++ 编译器 > 重置设置
- 构建工具
- 恢复默认值
- 代码帮助
For instructions on automatic code assistance for existing sources, see:
有关现有源的自动代码辅助的说明,请参阅:
C/C++ Projects Quick Start Tutorial:
http://netbeans.org/kb/docs/cnd/quickstart.html#makefileprojects
How to Configure Code Assistance When Creating a Project from Existing Code:
http://netbeans.org/kb/docs/cnd/configuring-code-assistance.html
C/C++ 项目快速入门教程:
http://netbeans.org/kb/docs/cnd/quickstart.html#makefileprojects
从现有代码创建项目时如何配置代码辅助:
http://netbeans.org/kb/docs/cnd/configuring-code-assistance.html
Now, configure the project options:
现在,配置项目选项:
- Right click on project > Properties
- Configuration: <All Configurations>
- Build
- C Compiler
- General
- Include Directories:
C:\Program Files (x86)\Example\1.0\include\shared
C:\Program Files (x86)\Example\1.0\include\other
C:\Program Files (x86)\Example\1.0\include
- Include Directories:
- Compilation Line
- Additional Options:
-std=c11 -g3 -pedantic -Wall -Wextra -O0
- Additional Options:
- General
- C++ Compiler
- General
- Include Directories:
C:\Program Files (x86)\Example\1.0\include\shared
C:\Program Files (x86)\Example\1.0\include\other
C:\Program Files (x86)\Example\1.0\include
- Include Directories:
- Compilation Line
- Additional Options:
-std=c++11 -g3 -pedantic -Wall -Wextra -O0
- Additional Options:
- General
- C Compiler
- OK.
- 右键单击项目> 属性
- 配置:<所有配置>
- 建造
- C 编译器
- 一般的
- 包括目录:
C:\Program Files (x86)\Example\1.0\include\shared
C:\Program Files (x86)\Example\1.0\include\other
C:\Program Files (x86)\Example\1.0\include
- 包括目录:
- 编译线
- 其他选项:
-std=c11 -g3 -pedantic -Wall -Wextra -O0
- 其他选项:
- 一般的
- C++编译器
- 一般的
- 包括目录:
C:\Program Files (x86)\Example\1.0\include\shared
C:\Program Files (x86)\Example\1.0\include\other
C:\Program Files (x86)\Example\1.0\include
- 包括目录:
- 编译线
- 其他选项:
-std=c++11 -g3 -pedantic -Wall -Wextra -O0
- 其他选项:
- 一般的
- C 编译器
- 好的。
For adding command-line options by default for all projects, see:
要默认为所有项目添加命令行选项,请参阅:
Any spaces in the path should be automatically escaped. Any backward slashes should be replaced with forward slashes automatically.
路径中的任何空格都应自动转义。任何反斜杠都应自动替换为正斜杠。
For example, the "All options" textbox in "Additional Options" looks like this:
例如,“附加选项”中的“所有选项”文本框如下所示:
-std=c11 -g3 -pedantic -Wall -Wextra -O0 -g -I/C/Program\ Files\ \(x86\)/Example/1.0/include/shared -I/C/Program\ Files\ \(x86\)/Example/1.0/include/other -I/C/Program\ Files\ \(x86\)/Example/1.0/include
If this does not work, you may have to fix the path and add the includes manually in the additional options. For example, replace /C/
with C:/
.
如果这不起作用,您可能需要修复路径并在附加选项中手动添加包含。例如,替换/C/
为C:/
.
-std=c11 -g3 -pedantic -Wall -Wextra -O0 -g -IC:/Program\ Files\ \(x86\)/Example/1.0/include/shared -IC:/Program\ Files\ \(x86\)/Example/1.0/include/other -IC:/Program\ Files\ \(x86\)/Example/1.0/include
If you are using Cygwin make
and if you try to clean or rebuild the project with colons in the command, you may get a *** multiple target patterns. Stop.
error message. According to the answers from Multiple target patterns?and Very simple application fails with "multiple target patterns" from Eclipse, "make
sees the :
in the path and thinks it is another target definition, hence the error."
如果您正在使用 Cygwin,make
并且如果您尝试在命令中使用冒号清理或重建项目,您可能会收到一条*** multiple target patterns. Stop.
错误消息。根据多个目标模式的答案?并且非常简单的应用程序因来自 Eclipse 的“多个目标模式”而失败,“make
看到:
路径中的 并认为它是另一个目标定义,因此出现错误。”
The workaround is to delete the generated build
and dist
folders every time before you build your project. However, this can be annoying, so you could try MinGW MSYS make
instead (not to be confused with MinGW make
, which is unsupported).
解决方法是在每次构建项目之前删除生成的build
和dist
文件夹。然而,这可能是恼人的,所以你可以尝试MinGW的MSYSmake
代替(不要与MinGW的混淆make
,这是不支持)。
For MinGW and MSYS configuration instructions, see:
有关 MinGW 和 MSYS 配置说明,请参阅:
Configuring the NetBeans IDE for C/C++/Fortran:
http://netbeans.org/community/releases/68/cpp-setup-instructions.html#mingw
为 C/C++/Fortran 配置 NetBeans IDE:
http://netbeans.org/community/releases/68/cpp-setup-instructions.html#mingw
For working with MinGW and Unicode, you should install the latest version of MinGW-w64. See:
要使用 MinGW 和 Unicode,您应该安装最新版本的 MinGW-w64。看: