NetBeans设置GCC编译器

12
当我点击项目属性时,我可以设置警告级别 (更多警告) 和 命令行 -> 附加选项 (-std=c99)。但是我希望所有我的C项目默认都具有这种选项,而不是每次创建新项目时手动设置它们。

screenshot


只是一个提示:虽然 XP1 是完全正确的,但在简单情况下,您可以使用 CFLAGS - user719662
3个回答

5

每个项目的配置属性都保存在\nbproject\configurations.xml(%UserProfile%\Documents\NetBeansProjects\ProjectName\nbproject\configurations.xml)文件中。

您可以在项目之间共享configurations.xml文件,这样您就不必更改并应用每个设置。


您可以创建一个默认项目并按照自己的喜好进行配置。而不是创建一个新项目,您可以将其复制,然后命名为其他名称。


如果您希望工具链属性适用于每个项目,则需要手动修改工具链定义或创建一个新工具链。

  • Generate shadow copies of the tool collection descriptors:

    • NetBeans > File > Exit.
    • Gain write access to modify %ProgramFiles%\NetBeans x\etc\netbeans.conf:
      • Start > Run > %ProgramFiles%\NetBeans x\.
      • Right click on the etc folder > Properties > Security > Edit... > Under "Group and user names", select the "Users" group > Under "Permissions for Users", for "Full control", enable "Allow" > OK > OK.
    • Open %ProgramFiles%\NetBeans x\etc\netbeans.conf in a text editor that can handle the newlines.

      • On the line starting with netbeans_default_options, add -J-Dcnd.toolchain.personality.create_shadow=true to the string of values.

        • For example, the line may now look like:

          netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.zip.disableMemoryMapping=true -J-Dcnd.toolchain.personality.create_shadow=true"

      • Save the file.
      • If you had imported settings from an older profile that had generated shadow copies previously to a 7.2+ profile, then you must open the toolchain.properties file in %Appdata%\NetBeans\x\config\Preferences\org\netbeans\modules\cnd\. In toolchain.properties, remove the line toolchain_shadow=true, and save.
        • If you do not do this step after upgrading and importing the NetBeans profile, NetBeans may not generate the shadow copies. Also, you may not be able to use any build tools, and you may get a "No compiler sets were found in the directory ..." error when you try to configure the C/C++ build tools.
      • Open and then close NetBeans.
      • On the line starting with netbeans_default_options, remove -J-Dcnd.toolchain.personality.create_shadow=true from the string of values. In other words, undo the edit to restore the file back to its original state.
      • Save the file.
  • Modify or create the toolchain definition:

    • Start > Run > %Appdata%\NetBeans\x\config\CND\ToolChain\ (7.2+) or %UserProfile%\.netbeans\x\config\CND\ToolChain\ (7.1.2-).
    • Locate the corresponding XML file for your toolchain.
      • For example, the MinGW toolchain definition file is MinGW.xml.
    • Open the XML file in a text editor that can handle the newlines.
    • Within the c element, there is a development_mode element containing the different development mode option elements. You can modify the flags for a particular development mode by modifying the flags attribute.

      • For example, when you add the -std=c11 -g3 -pedantic -Wall -Wextra -O0 flags, the attributes may look like this:

        <development_mode>
            <fast_build flags="-std=c11 -g3 -pedantic -Wall -Wextra -O0"/>
            <debug default="true" flags="-std=c11 -g3 -pedantic -Wall -Wextra -O0 -g"/>
            <performance_debug flags="-std=c11 -g3 -pedantic -Wall -Wextra -O0 -g -O"/>
            <test_coverage flags="-std=c11 -g3 -pedantic -Wall -Wextra -O0 -g"/>
            <diagnosable_release flags="-std=c11 -g3 -pedantic -Wall -Wextra -O0 -g -O2"/>
            <release flags="-std=c11 -g3 -pedantic -Wall -Wextra -O0 -O2"/>
            <performance_release flags="-std=c11 -g3 -pedantic -Wall -Wextra -O0 -O3"/>
        </development_mode>
        
    • Within the cpp element, there is a development_mode element containing the different development mode option elements. You can modify the flags for a particular development mode by modifying the flags attribute.

      • For example, when you add the -std=c++11 -g3 -pedantic -Wall -Wextra -O0 flags, the attributes may look like this:

        <development_mode>
            <fast_build flags="-std=c++11 -g3 -pedantic -Wall -Wextra -O0"/>
            <debug default="true" flags="-std=c++11 -g3 -pedantic -Wall -Wextra -O0 -g"/>
            <performance_debug flags="-std=c++11 -g3 -pedantic -Wall -Wextra -O0 -g -O"/>
            <test_coverage flags="-std=c++11 -g3 -pedantic -Wall -Wextra -O0 -g"/>
            <diagnosable_release flags="-std=c++11 -g3 -pedantic -Wall -Wextra -O0 -g -O2"/>
            <release flags="-std=c++11 -g3 -pedantic -Wall -Wextra -O0 -O2"/>
            <performance_release flags="-std=c++11 -g3 -pedantic -Wall -Wextra -O0 -O3"/>
        </development_mode>
        
    • Save the file.

要在不同的平台上找到netbeans.conf配置文件,请参见以下内容:

要在不同的平台上找到用户目录,请参见以下内容:

有关工具集描述符的信息,请参见以下内容:


就我所知,我使用的一种通用IDE无关解决方案是一个老技巧——要么使用CFLAGS,要么(大多数工具链独立)只需创建一个.exe文件,该文件调用system并将编译器/链接器作为第一个参数、配置文件中的其他参数以及最后添加所有实际的argv参数。要么创建一个仅包含重定向器的全新目录,要么将所有旧的.exe文件重命名为其他名称。 - user719662

1

首先从Code::Blocks IDE下载MSYS 1.0.11下载并安装Code::Blocks集成开发环境。

所有设置都将自动配置,但您必须从中选择“make”命令。

C:\msys\1.0\bin\make.exe

enter image description here


4
这并没有回答问题。@gameboy谈论的是默认项目属性,而不是构建工具。 - XP1

0

在Windows 7 Professional下使用NetBeans 8.1和MinGW(gcc),我找到了这个文件

C:\Users\Username\AppData\Roaming\NetBeans\8.1\config\Preferences\org\netbeans\modules\cnd*toolchain.properties*,

但是我找不到文件夹

C:\Users\Username\AppData\Roaming\NetBeans\8.1\config\CND

(所以我找不到C:\ Users \ Username \ AppData \ Roaming \ NetBeans \ 8.1 \ config \ CND \ ToolChain)

我找到了这个文件夹

C:\Users\Username\AppData\Roaming\NetBeans\8.1\config\Preferences\org\netbeans\modules\cnd

但那里没有MinGW.xml文件。我在安装NetBeans(和MinGW)的硬盘驱动器上找不到这个MinGW.xml文件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接