Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netbeans environment variables for C++ makefile

I have a simple makefile which calls the C++ compiler as $(CXX), which is set in my ~/.profile script. Netbeans seems to have a sophisticated toolchain manager, yet it seems to resolve $CXX as just c++ no matter what.

How can I set $CXX properly, or is there another variable set by Netbeans that my makefile can detect? (yuck)

Edit: right-clicking the makefile in the navigator allows me to specify an environment, although there seems to be only room for one line of input. Specifying CXX=/usr/local/bin/g++ fixes the problem, but this is far from optimal.

like image 368
Potatoswatter Avatar asked Feb 13 '13 03:02

Potatoswatter


1 Answers

I'll just describe what I usually do when I work with C++ in NetBeans. At first, for each project I create a simple makefile like this:

MAIN = <my main target>
CFLAGS = -g -std=c++0x

include ${MAKELIBHOME}/MINGW32.inc
include ${MAKELIBHOME}/WINDOWS.inc

build: ${MAIN}

clean:; rm -fr <files to remove>

The environment variable MAKELIBHOME is set outside of NetBeans. The directory ${MAKELIBHOME} contains a number of include files for the make, for example the file MINGW32.inc looks like this:

CC = g++

CFLAGS += -W -DLITTLE_ENDIAN=1
LDLIBS += -lws2_32

.SUFFIXES: .o .c .cpp

.c:     ;${CC} ${CFLAGS} ${LDFLAGS} $< -o latest ${LDLIBS}
.cpp:   ;${CC} ${CFLAGS} ${LDFLAGS} $< -o latest ${LDLIBS}

.c.o:   ;${CC} ${CFLAGS} -c $<
.cpp.o: ;${CC} ${CFLAGS} -c $<

These inc-files are the same for all NetBeans projects. There are no absolute paths here, so the make will use the PATH variable to locate a GCC toolset, but of course you can use absolute paths to choose the toolset you like (or include a different inc-file - I'd prefer this way).

All this works on my Windows machine, but the Linux configuration looks very similar - I just need to include another set of inc-files to all my main makefiles. Also, this setup allows me to call the make from the command line.

I hope it helps, ~AY

like image 53
HEKTO Avatar answered Sep 28 '22 08:09

HEKTO