Running make for a C ++ project under Eclipse

I am developing a C ++ application under Ubuntu 10.10 using g ++ and automake. For this program, I have two cpp files (main.cpp and forward.cpp, the last one is a test class) and forward.h; I also have the following make file:

main: \ forward.o g++ -fPIC -g -Wall -D_REENTRANT -fno-exceptions -I/usr/local/Aria/include/ -L/usr/local/Aria/lib -lAria -lpthread -ldl -lrt \ -o simple_controller \ main.cpp \ forward.o %.o : %.cpp g++ -c -g -Wall -D_REENTRANT -fno-exceptions -I/usr/local/Aria/include/ $< -o $@ clean: rm -fv *.o rm -fv */*.o 

When I copy all of these four files to the same directory and call "make" from the command line (bash), then g ++ is called and my program will compile correctly.

Ok, now I wanted to do the same in Eclipse. So I created a new unmanaged C ++ project under Eclipse, so that I can provide my own makefile (the same as above). Unfortunately, when I now use the Create All option in Eclipse, I can see the following console output:

 make make: *** No rule to make target `forward.o', needed by `main'. Stop. 

Since I'm new to C ++ development on Linux using g ++ and make files, I really don't understand the problem. I thought that everything that was needed to compile my application was written in a make file, since it works fine from the command line. But it seems like I cannot copy the same makefile 1: 1 to an Eclipse project.

Any ideas on what I don't see here?
Thanks in advance for your help!

+4
source share
3 answers

when you build the project, eclipse runs the make all command, so you will either need to modify the project to use main instead of everyone to use eclipse for the purpose, or add the entire rule to your makefile, which refers to return to the main rule. I would also add a command under a clean step to remove the executable.

Modified Makefile:

 main: \ forward.o g++ -fPIC -g -Wall -D_REENTRANT -fno-exceptions -I/usr/local/Aria/include/ - L/usr/local/Aria/lib -lAria -lpthread -ldl -lrt \ -o simple_controller \ main.cpp \ forward.o %.o : %.cpp g++ -c -g -Wall -D_REENTRANT -fno-exceptions -I/usr/local/Aria/include/ $< -o $@ clean: rm -fv *.o rm -fv */*.o rm -fv simple_controller all: main 
+1
source

So, I found the problem now - Eclipse places the makefile in a different directory than the "src" folder, where all the source code files are located. Therefore, make did not find the .cpp and .h files needed for compilation. Now I ended up in something like this:

 ... forward.o : ../src/forward.cpp ../src/forward.h ... 

Is there any way to say that it should also look into the .. / src folder, even if not explicitly specified?

+1
source

You can tell make to change directories with the -C option.

For example, if your source is in src / and your makefile is in the src / parent directory, you can simply do:

 make -C .. 

Note. Eclipse is not used specifically, but there is usually a way to add command line switches and parameters to the build command somewhere in the IDE parameters.

(The answer is based on the second part of your question, where you indicate that the problem is that the makefile is in a different folder, and then your source.)

0
source

Source: https://habr.com/ru/post/1338560/


All Articles