Setting Default NetBeans Options (-std=c99, -Wall) for C programs - c

I have NetBeans 6.9 installed and working fine on Ubuntu Linux 11.10. My goal is to set compiler options like -Wall and -std=c99 to be used by default. Currently, I have to right click on my project -> Properties -> C Compiler -> Warning Level to "More Warnings" and add -std=c99 to Additional Options. This is obviously a pain when creating many projects, and I'm sure there is a way to make all of this the default.
I found this thread which relates closely to my question. However, the only answer involves installing Code::Blocks and MSYS 1.0.11, which doesn't make much sense to me. I don't see how installing another IDE will help me, and MSYS seems unnecessary, as I am already using Linux.
I have tried every reasonable search term I can imagine, and am very surprised how little info I have turned up. It seems like most everyone who uses NetBeans should have to change this type of thing at some point. Terms I'm searching for: 'NetBeans -std=c99 default', 'NetBeans set default compile options', 'how to make NetBeans use c99 by default' and 'Code::Blocks settings into NetBeans'.

Here are some different things that you can do:
Copy and share the configuration files between projects, so you won't have to set every setting.
Create a default project, and configure however you like it. When you want to create a new project, just copy the default project and rename it to something else.
Modify your toolchain properties.
For details, see here:
NetBeans settings for GCC

You can create a Project Template Module. I was aware this is possible but didn't try it before, and this link is explaining how to do it;
https://blogs.oracle.com/seapegasus/entry/tip_create_your_own_project
(First you need NetBeans with platform SDK, not just C/C++ Bundle.)
I followed steps;
Open/Create your project with settings you want to use.
Create a NetBeans module project, choose a Code Base Name, i gave my.templates.ctemplate1
Add "Module Development > Project Template" to the module project. Choose your C project in "Select Project" step.
At next step select the Category as C/C++ and give a name for template i used MyCTemplate1.
Right click on module project and select "Create NBM", it will create my-templates-ctemplate1.nbm in the build folder of the module project.
Tools > Plugins > Downloaded , click "Add Plugin" and point to the nbm file in the build folder. Select install, it will give warnings because it's not signed.
When you want to create a new C/C++ project you will see your template in the wizard which will have all the settings as your first C project has.
Enjoy other possibilities; files, folders in original project will be there.

Have you tried editing your netbeans.conf file (for me, it's in /usr/local/netbeans-7.0.1/etc/netbeans.conf) and adding the options you need to the netbeans_default_options line? From looking at my version of the file, you might need to prepend -J to the switches (hence -Wall would become -J-Wall.)

Related

What settings to use when installing MinGW-W64 to build FuTTY?

I want to build FuTTY.
The original author uses Visual Studio, I want to avoid that. I found out that apparently I have to:
Add MinGW/bin and MinGW/msys/1.0/bin to the PATH
run perl mkfiles.plto restore some missing makefiles
Remove -mno-cygwin from Makefile.cyg
Add XFLAGS = -DCOVERITY to Makefile.cyg
run make -f Makefile.cyg putty.exe from the windows directory
This works for building the original PuTTY, but is not enough for FuTTY.
It complains that KEY_WOW64_32KEY is undeclared. When I googled that, I found that apparently this means you need MinGW-W64.
At this point I'm making wild guesses, but I think the selector shown below means that the MinGW-W64 project is about making all kinds of toolchains run on Windows 64 bit and if I want something that works with PuTTY's MinGW makefile, I need this:
Right? So after downloading that, I am presented with questions I cannot answer:
I'm using more handy tool chain distribution MSYS2

program g++ not found in path

I am using Eclipse for a C project. I created a new Project by going to New->C project->Executable->Empty Project, Linux gcc toolchain.
When I add a new .c file, I get "program 'g++' not found in path".
How do I get rid of this? I'm not even using C++.
I had similar problem and it is solved by
Installing g++ The GNU C++ complier using ubuntu software centre and
Changing in -
Window -> Preferences -> C/C++ -> Build -> Settings -> Discovery -> CDT GCC Build in Complier Settings [Shared]
From: ${COMMAND} -E -P -v -dD "${INPUTS}"
To : /usr/bin/${COMMAND} -E -P -v -dD "${INPUTS}"
I hope it helps.
For posterity I'm going to post my own solution to this problem. None of the answers above or on related StackOverflow questions helped; most referred to menu entries that didn't exist, and the ones I could try did nothing. I searched other sites as well; there were about 6 different answers repeated many times, and none helped.
Short answer: I blew away the Eclipse install and replaced it. Then it worked. For me at least it wasn't a project or configuration option (at least not one I could get to from the GUI); something in the Eclipse program folder had gotten tweaked and only a new install could repair the problem.
I'm doing Android development using the "ADT" (Android Developer Tools) build of Eclipse. I did something to the configuration that made it start giving the above error (actually two errors, for gcc and g++ both). And I tried plenty of potential solutions (in addition to my own searching for options that might help) with no success.
Thing is, I didn't NEED gcc or g++ in the path. I'm doing Android development, and while both are used in the build process, I'm not using Eclipse to do the builds; I use the Android build system. And the C/C++ Build/Discovery options didn't even give me an option for setting paths for gcc or g++. Other answers I found elsewhere referenced menu entries that don't exist, and most seemed to be about helping people to use the normal C/C++ build within Eclipse, which I didn't need to do.
So I used this opportunity to download the latest ADT package from Google, and then I ran the new one, importing the existing project into a new workspace (just in case the old workspace was corrupted or otherwise part of the problem). No more annoying gcc/g++ error.
I got the same error while I was using "Eclipse IDE for C/C++ Developers."
Install Eclipse from Ubuntu Software Center and then download and install Eclipse CDT.
To install CDT, open Eclipse -> Help -> Install New Software -> Add -> Archieve...
Then give CDT path to there. That's all
I was able to fix the problem by selecting
project(right click in Project Explorer on your project)->properties->Tool Chain Editor
and switching the Current Toolchain: to Android GCC and Current Buolder: to Android Builder
I also had the same problem. I did not have this error running my program but after a adding, including different Api and paths , probably unintentionally some changes happened in my Path that I could not fix it.
I could fix this error by going to Properties and just restore default for all the Tabs.

Creating Project from existing source code in Eclipse

I am new to Eclipse. Working on school project from source code provided by instructor. Project compiles without problems using provided makefile, but I want to compile/edit inside of Eclipse.
I have tried to import as Makefile project, but right away getting an error
make: *** No rule to make target `all'.
Here is a basic list of files.
Main:
Makefile
mm.{c,h}
malloc.c
mdriver.c
short{1,2}-bal.rep
Supporting:
config.h
fsecs.{c,h}
clock.{c,h}
fcyc.{c,h}
ftimer.{c,h}
memlib.{c,h}
Why I can't simply "Import" source, as I can do it in Visual Studio ?
Thanks !
CDT will attempt to build the project using make all, and it seems that your Makefile does not have that target. Easiest is to add:
all: your-target-to-make-stuff
to your Makefile. If you want to configure how CDT invokes make, you can right-click on the project, select Properties → C/C++ Build. Under the Behavior tab, you can select which make targets CDT should invoke when building and cleaning.
I don't have an Eclipse with C/C++ plugin at my hands right now, but I have an idea what it could be:
It appears that your Eclipse is starting make with the specific target 'all', which doesn't seem to exist in the Makefile - you should be able to reproduce this behavior on the command line with the command make all instead of just make.
If this is the case, there are two solutions: one is to modify the Makefile to introduce a target 'all'; or modify the C/C++ builder settings in Eclipse to execute the make without any argument.
You can install the C/C++ for developers plugin.
Or in many cases I would use Ant to create or call make files.

Eclipse + CDT + Cygwin: How do you fix the "Multiple targets" bug?

UPDATE 1:
My original post was too long and obscured the real problem. I have discovered exactly what is causing the "Multiple targets" bug when Make is called.
UPDATE 2:
I found out that this 'Multiple Targets' bug is caused by GNU Make version 3.8.1 (see here1 and here2). GNU Make 3.8.1 is the current GNU Make released with Cygwin. To summarize the link: The old v3.8.0 handled windows paths fine and the newer v3.8.1 reports errors for windows paths (maybe it's a passive aggressive jab from the FSF?).
When you start a new project in Eclipse+CDT+Cygwin w/o external includes/libraries, everything works fine for me.
As soon as I try to use an external include/library I get the "Multiple targets" bug.
Here is exactly the steps needed to reproduce the bug on Windows+Eclipse+CDT+Cygwin:
Project project properties --> C/C++ Build --> Settings --> Tool Settings --> Cygwin C Compiler --> Includes --> Include Paths (-I) -- > Add Button --> Pick directory --> "C:\dir1\dir2"
I hit build.
It builds with no errors the first time.
I hit build again... I get build errors "Multiple targets. Stop.".
I click on the error.
Eclipse pulls up a makefile. The error happens when make sees the windows path for the new include file from the external library:
# NOTE: Error happens when the first "C:/" occurs
src/main.d src/main.o: ../src/main.c C:/dir1/dir2/ExternalLibrary.h
The reason for Make getting an error "Multiple targets" is because it sees the ":" which is part of the Make syntax for declaring a target. When there are two ":", Make errors out because it doesn't know what to do with "Multiple targets."
I can not edit the makefiles manually because they are immediately regenerated and overwritten [UPDATE: by Eclipse-CDT]. Given that I can't manually edit the makefile.
Is there any way for Eclipse to NOT use the "C:\" path? or tell make to ignore the "C:\" path?
Is this an Eclipse+CDT+Cygwin bug?
If you use Eclipse+CDT+Cygwin... please lend a hand (I don't want to use Visual Studios...)! Maybe I am using Eclipse+CDT+cygwin wrong? How do YOU get External Library includes to work?
*Very very frustrated*
Trying to stay Open-Source and cross-platform user,
Trevor
Turns out the "multiple targets" issue is caused by the current version of GNU Make installed from Cygwin. GNU Make 3.8.1 is the current GNU Make released with Cygwin.
The GNU Make 3.8.1 does not handle windows paths that contain "C:\". So every time your make file has a windows path with "C:\" you get a build error "multiple targets".
The solution I ended up doing is to download a fixed GNU Make v3.8.1. See Here1 or Here2. Then Eclipse+CDT+Cygwin worked fine again.
Update (05-feb-2015):
With an updated cygwin and a new Make (4.0.x) then the problem goes away.
https://superuser.com/questions/154418/where-do-i-get-make-for-cygwin
Had a such a problem, too. Problem was that I included paths on the project settings. Then I had absolute paths. When including the paths in the folder settings with relative paths it worked fine.
I still Got the same problem with eclipse/CDT Juno after update cygwin
to fix it:
you need make 3.80-1 or older and this needs cygintl-2.dll.
download make3.80-1 from
http://www.filewatcher.com/m/make-3.80-1.tar.bz2.286814-0.html
and the needed Dll from
http://www.dllguru.com/cygintl-2.dll.html
extract it somewhere
rename your make in cygwin/bin to makeVersion e.g. make3.82.90
copy cygintl-2.dll and make into cygwin/bin
try build your project in eclipse twice, the problem should be disappeared
gerdi

How to organise a C project in Eclipse /w multiple binaries?

I'm in the process of converting a project to Eclipse CDT, it consists of 2 (static) libraries and produces about 12 binaries, a few of the binaries have 2-3 different build configurations, and is built by scons
How should I structure this in an Eclipse workspace ? 1 project for everything ? 1 project for each of the binaries/libs ? Something else ?
I'd suggest you use CMAKE for this problem, It should be able target target the Eclipse build system. If not, it can generate a normal 'make' config for you. It is far better to go down this route since its more portable in the long term, and writing a hierarchical build system is quite straight forward.
I personally have used Eclipse CDT before, but only in makefile mode i.e. to build anything I'd manually run the makefile. Basically I used Eclipse as a glorified editor. Here's how I worked things:
Everything part of the otherall solution came under the same workspace. Each library/binary was its own directory and project, so that I could make each as required. I also had a separate folder (project) for tests with a makefile that built all the test exes I wanted to run so I could do valgrinds on simple bits of it.
As I said, I used make and not Eclipse CDT's built-in building routines - to that end I'd say it really doesn't matter how you structure it - do whatever makes sense / conforms best to the UNIX principles.

Resources