且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Windows 上为 NetBeans 和 gcc 添加库包含路径?

更新时间:2022-02-14 08:32:18

比如你想把C:Program Files (x86)Example1.0include中的目录添加为包含路径.

For example, you want to add the directories in C:Program Files (x86)Example1.0include as the include paths.

首先设置代码辅助:

  • NetBeans > 工具 > 选项 > C/C++ > 代码帮助
    • C 编译器 > 包含目录:
      • C:Program Files (x86)Example1.0includeshared
      • C:Program Files (x86)Example1.0includeother
      • C:Program Files (x86)Example1.0include
      • C:MinGWlibgccmingw324.7.0include
      • C:MinGWinclude
      • C:MinGWlibgccmingw324.7.0include-fixed
      • ...
      • C:Program Files (x86)Example1.0includeshared
      • C:Program Files (x86)Example1.0includeother
      • C:Program Files (x86)Example1.0include
      • C:MinGWlibgccmingw324.7.0includec++
      • C:MinGWlibgccmingw324.7.0includec++mingw32
      • C:MinGWlibgccmingw324.7.0includec++ackward
      • C:MinGWlibgccmingw324.7.0include
      • C:MinGWinclude
      • C:MinGWlibgccmingw324.7.0include-fixed
      • ...

      C:MinGW... 目录只是示例.不要实际添加它们.NetBeans 应该已经自动检测并添加了 MinGW 目录.如果没有,请尝试重置设置:

      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:

      • NetBeans > 工具 > 选项 > C/C++
        • 代码帮助
          • C 编译器 > 重置设置
          • C++ 编译器 > 重置设置
          • 恢复默认设置

          有关现有源代码自动辅助的说明,请参阅:

          For instructions on automatic code assistance for existing sources, see:

          • C/C++ 项目快速入门教程:

          • 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/配置代码协助.html

          现在,配置项目选项:

          • 右键单击项目 > 属性
            • 配置:
            • 构建
              • C 编译器
                • 一般
                  • 包括目录:
                    • C:Program Files (x86)Example1.0includeshared
                    • C:Program Files (x86)Example1.0includeother
                    • C:Program Files (x86)Example1.0include
                    • 其他选项:
                      • -std=c11 -g3 -pedantic -Wall -Wextra -O0
                      • 一般
                        • 包括目录:
                          • C:Program Files (x86)Example1.0includeshared
                          • C:Program Files (x86)Example1.0includeother
                          • C:Program Files (x86)Example1.0include
                          • 其他选项:
                            • -std=c++11 -g3 -pedantic -Wall -Wextra -O0

                            要为所有项目默认添加命令行选项,请参阅:

                            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
                            

                            如果这不起作用,您可能需要修复路径并在附加选项中手动添加包含.例如,将 /C/ 替换为 C:/.

                            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:/.

                            -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
                            

                            如果您正在使用 Cygwin make 并且如果您尝试在命令中使用冒号清理或重建项目,您可能会得到 *** 多个目标模式.停止. 错误信息.根据 多目标模式?非常简单的应用程序因多目标模式"而失败;来自 Eclipsemake 在路径中看到 : 并认为它是另一个目标定义,因此出现错误."

                            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."

                            解决方法是在每次构建项目之前删除生成的 builddist 文件夹.但是,这可能很烦人,因此您可以尝试改为尝试 MinGW MSYS make(不要与 MinGW 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).

                            有关 MinGW 和 MSYS 配置说明,请参阅:

                            For MinGW and MSYS configuration instructions, see:

                            • 为 C/C++/Fortran 配置 NetBeans IDE:

                            • Configuring the NetBeans IDE for C/C++/Fortran:

                            http://netbeans.org/community/releases/68/cpp-setup-instructions.html#mingw

                            要使用 MinGW 和 Unicode,您应该安装最新版本的 MinGW-w64.见:

                            For working with MinGW and Unicode, you should install the latest version of MinGW-w64. See: