8

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
XP1
  • 6,910
  • 8
  • 54
  • 61

1 Answers1

13

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

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.

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)\Example\1.0\include\shared
            • C:\Program Files (x86)\Example\1.0\include\other
            • C:\Program Files (x86)\Example\1.0\include
        • Compilation Line
          • Additional Options:
            • -std=c11 -g3 -pedantic -Wall -Wextra -O0
      • 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
        • 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:

Community
  • 1
  • 1
XP1
  • 6,910
  • 8
  • 54
  • 61
  • @JesseGood, how about `-std=c11`? So what other problems were you thinking about? Just because information exists somewhere else does not mean that it should not exist on Stack Overflow. I have also added more information about `make` issues that may not exist on the NetBeans website. – XP1 Jul 24 '12 at 02:39
  • On code assistance, http://netbeans.org/kb/docs/cnd/quickstart.html and http://netbeans.org/kb/docs/cnd/configuring-code-assistance.html say that code assistance can be automatically configured from existing sources. However, if I create a new C project, type `#include ` at the top, and try to compile, it says `fatal error: example.h: No such file or directory`. It is not automatic. It does not magically know where `example.h` lives. I have to configure the location of `example.h` manually. – XP1 Jul 24 '12 at 02:40
  • @JesseGood The `C:\MinGW\...` directories are only there to demonstrate what it looks like on my computer. Of course, it would be ridiculous to add them if they already exist. I have added your suggestions about the compiler flags. – XP1 Jul 24 '12 at 03:22
  • The spaces in `C:\Program Files (x86)\Example\1.0\include` should be automatically escaped. As you can see from the "All options" textbox: `C:/Program\ Files\ \(x86\)/Example/1.0/include`. Some SDKs and headers install in `C:\Program Files (x86)`. – XP1 Jul 24 '12 at 03:25
  • Last Comment: Looks a lot better (removed the downvote). Also, just using forward slashes `/` to begin with might be better to avoid problems. Hopefuly somebody finds this useful (I will delete my old comments as they just take up space). – Jesse Good Jul 24 '12 at 03:33
  • This solution does not work. Still complains the included file does not exist. – Dissident Rage Mar 05 '14 at 16:01
  • How to include directories and all it's sub-directories at once? – Vivek Kumar Dec 28 '14 at 10:25
  • There are no "C++ compiler" and "C compiler" sections under "Build" in Project -> Properties. Though under "Code Assistance" they are present. Using Netbeans IDE 18 with C++ plugin. – noname7619 Aug 21 '23 at 06:27