Netbeans environment variables for C ++ makefile

I have a simple make file that calls the C ++ compiler as $(CXX) , which is installed in my ~/.profile script. Netbeans seems to have a sophisticated tool manager, but it looks like it resolves to $CXX as soon as c++ no matter what.

How can I set $CXX or is there another variable set by Netbeans that my make file can define? (Fu)

Edit: right-clicking on the makefile in the navigator allows me to specify the 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.

+6
source share
3 answers

I will simply describe what I usually do when I work with C ++ in NetBeans. First, for each project, I create a simple make file as follows:

 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 MAKELIBHOME environment variable is set outside of NetBeans. The $ {MAKELIBHOME} directory contains several include files for make, for example, the MINGW32.inc file 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} .co: ;${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 make will use the PATH variable to find the GCC toolkit, but of course you can use the absolute paths to select the toolkit you need (or include another inc file - I would prefer this path)).

All this works on my Windows machine, but the Linux configuration looks very similar - I just need to include a different set of inc files in all my main make files. In addition, this setting allows me to invoke make from the command line.

Hope this helps, ~ A.Ya.

+3
source

This is an old post. However, I recently discovered the same problem, and I found an alternative based on @HEKTO's answer.

I use PETSc, a library for solving large sparse matrix systems. Their build system requires that you use "include" in your makefile, which depends on two environment variables: PETSC_DIR and PETSC_ARCH, which must be set in your environment .... or you can pass them as parameters to your make command! this is what i did.

I took the makefile generated by NetBeans and at the very end I added that include:

 include ${PETSC_DIR}/conf/variables 

Note how this depends on the definition of PETSC_DIR. In addition, this includes massive use of this and PETSC_ARCH throughout.

So now in NetBeans I am setting it up to pass these variables: Tools-> Options: On the Project Settings tab, I fill out the Make Settings text box: PETSC_DIR = / path / to / petsc PETSC_ARCH = some-arch

In addition, now you can start using these environment variables (and others defined in $ {PETSC_DIR} / conf / variables in your project options. For example, for my included files I do (right-click on the project, then "Properties" )): In the section "Compiler C", "Include Directories" I put: $ {PETSC_DIR} / include

And under "Linker", "Libraries" I put: $ {PETSC_LIB} (defined in the include file above).

Now I can create and run my project from NetBeans. If my version of PETSc changes, I only need to change the definition of the variables passed to make, and everything else will be allowed.

Hope this can help someone. It definitely worked for me. And the nice part is that I can pass my code to other people, and they can be compiled from the command line using "make" as usual (without NetBeans) and defining the above environment variables. Compilation now has no hard-coded paths.

+2
source

I had a very similar problem on linux where Netbeans did not capture environment variables from bash.

Solution: run netbeans from bash.

I'm not sure what the equivalent is on a Mac, but the idea is simple: start Netbeans from a terminal that has already set environment variables.

+1
source

All Articles