Eclipse Makefile: Make Variables are skipped

196 views Asked by At

I have a project with a Makefile in it, on Unix console it works fine, compiles, builds and I can run the binary at the end.

I imported the project into Eclipse workspace and somehow Makefile module of Eclipse cannot build the project now. It gives the following error:

g++: error: /src/main: No such file or directory

Whereas there should have been

g++ -I $(APR_INCLUDE) -I $(CMS_HOME)/src/main 

which uses two make variables. I already put them before this line and define them as :

export APR_INCLUDE=/usr/include/apr-1
export CMS_HOME=~/Desktop/activemq-cpp-library-3.8.4

Same Makefile is fine with console, but not with Eclipse, which is weird.

Any thoughts?

Here is where I put my export lines:

obstacleDetection_cpp: src/obstacleDetection.cpp protoc_middleman
    export APR_INCLUDE=/usr/include/apr-1
    export CMS_HOME=~/Desktop/activemq-cpp-library-3.8.4
    g++ -I  $(APR_INCLUDE) -I $(CMS_HOME)/src/main -g -o src/obstacleDetection.o -c src/obstacleDetection.cpp
    cd libs && cp $(CMS_HOME)/src/main/.libs/libactivemq-cpp.so.18.0.4 . && ln -sf libactivemq-cpp.so.18.0.4 libactivemq-cpp.so.18
    g++ -L $(CMS_HOME)/src/main/.libs/ -g -o bin/obstacleDetection src/obstacleDetection.o src-gen/Point.pb.cc src-gen/Point.pb.h -lactivemq-cpp -lssl -lprotobuf -pthread
    @echo "Success. Run the executable from the binary directory with: LD_LIBRARY_PATH=../libs/ ./obstacleDetection"
1

There are 1 answers

1
MadScientist On BEST ANSWER

This is not right:

obstacleDetection_cpp: src/obstacleDetection.cpp protoc_middleman
        export APR_INCLUDE=/usr/include/apr-1
        export CMS_HOME=~/Desktop/activemq-cpp-library-3.8.4
        g++ $(APR_INCLUDE) -I $(CMS_HOME)/src/main ...

All lines in the recipe (that is, lines that are indented with a TAB in a target context like this) are passed to the shell. These are not make variable assignments. There are two things wrong with that:

First, each logical line in the recipe is passed to a new shell. That means any changes to the process context (such as the environment or the working directory) are present only for the duration of that logical line; once the shell processing that line exits, all those changes are lost. So, these lines have no impact: they set an environment variable in the shell, then the shell exits and that setting is gone.

Second, the variable references you make in your compile line, such as $(APR_INCLUDE), are make variable references, not environment variable references. So even if those environment variable assignments still had effect, they would not be used because you're not referring to environment variables here.

You want to create make variable assignments. That can only be done outside of a recipe. Also, you don't need to export them because only make needs to see them (make will expand them before invoking the shell). So, your makefile should look like this:

APR_INCLUDE = /usr/include/apr-1
CMS_HOME = $(HOME)/Desktop/activemq-cpp-library-3.8.4

obstacleDetection_cpp: src/obstacleDetection.cpp protoc_middleman
        g++ -I  $(APR_INCLUDE) -I $(CMS_HOME)/src/main -g -o src/obstacleDetection.o -c src/obstacleDetection.cpp
        cd libs && cp $(CMS_HOME)/src/main/.libs/libactivemq-cpp.so.18.0.4 . && ln -sf libactivemq-cpp.so.18.0.4 libactivemq-cpp.so.18
        g++ -L $(CMS_HOME)/src/main/.libs/ -g -o bin/obstacleDetection src/obstacleDetection.o src-gen/Point.pb.cc src-gen/Point.pb.h -lactivemq-cpp -lssl -lprotobuf -pthread
        @echo "Success. Run the executable from the binary directory with: LD_LIBRARY_PATH=../libs/ ./obstacleDetection"