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
308 views
in Technique[技术] by (71.8m points)

c - NetBeans settings for GCC

When I click on project properties I can set Warning level (More Warnings) and Command Line -> Additional Options (-std=c99). But I want that all my C project have that kind of options by default without manually setting them everytime I create new project.

screenshot

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

For each project, the configuration properties are saved in the bprojectconfigurations.xml (%UserProfile%DocumentsNetBeansProjectsProjectName bprojectconfigurations.xml) file.

You could share the configurations.xml file between projects so that you won't have to change and apply every setting.


You could create a default project and configure it however you like. Instead of creating a new project, you could copy it, and name it something else.


If you want the toolchain properties to apply to every project, you will need to manually modify your toolchain definition or create a new one.

  • Generate shadow copies of the tool collection descriptors:

    • NetBeans > File > Exit.
    • Gain write access to modify %ProgramFiles%NetBeans xetc etbeans.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 xetc etbeans.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%NetBeansxconfigPreferencesorg etbeansmodulescnd. 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%NetBeansxconfigCNDToolChain (7.2+) or %UserProfile%.netbeansxconfigCNDToolChain (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.

For finding the netbeans.conf configuration file on different platforms, see:

For finding the user directories on different platforms, see:

For information on tool collection descriptors, see:


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

...