Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

c++ - How to add a library include path for NetBeans and gcc on Windows?

How to add a library include path for NetBeans and gcc on Windows?

Using:

  • NetBeans 7.1.2
  • MinGW (mingw-get-inst-20120426.exe)
  • gcc 4.7.0
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

First, set up code assistance:

  • NetBeans > Tools > Options > C/C++ > Code Assistance
    • C Compiler > Include Directories:
      • 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++ Compiler > Include Directories:
      • 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
      • ...
    • OK.

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 > Tools > Options > C/C++
    • Code Assistance
      • C Compiler > Reset Settings
      • C++ Compiler > Reset Settings
    • Build Tools
      • Restore Defaults

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


Now, configure the project options:

  • Right click on project > Properties
    • Configuration: <All Configurations>
    • Build
      • C Compiler
        • General
          • Include Directories:
            • C:Program Files (x86)Example1.0includeshared
            • C:Program Files (x86)Example1.0includeother
            • C:Program Files (x86)Example1.0include
        • Compilation Line
          • Additional Options:
            • -std=c11 -g3 -pedantic -Wall -Wextra -O0
      • C++ Compiler
        • General
          • Include Directories:
            • C:Program Files (x86)Example1.0includeshared
            • C:Program Files (x86)Example1.0includeother
            • C:Program Files (x86)Example1.0include
        • Compilation Line
          • Additional Options:
            • -std=c++11 -g3 -pedantic -Wall -Wextra -O0
    • OK.

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

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

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

For MinGW and MSYS configuration instructions, see:

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...