-1

I have an Eclipse C++ project which initially has first.cpp. Then second.cpp is added and should be linked to the original file. Using Eclipse building tool, I got this output:

make all 
Building file: ../src/first.cpp
Invoking: GCC C++ Compiler
g++ -I/home/workspace/first/src -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/first.d" -MT"src/first.o" -o "src/first.o" "../src/first.cpp"
Finished building: ../src/first.cpp
 
Building file: ../src/second.cpp
Invoking: GCC C++ Compiler
g++ -I/home/workspace/first/src -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/second.d" -MT"src/second.o" -o "src/second.o" "../src/second.cpp"
Finished building: ../src/second.cpp
 
Building target: first
Invoking: GCC C++ Linker
g++ -L/usr/local/lib -o "first"  ./src/first.o ./src/second.o
Finished building target: first

How can I get Eclipse to compile this way?

g++ first.cpp second.cpp -o first

Update

I am asking how to make a single binary from multiple source files, not building multiple binaries with multiple source files.

halfer
  • 19,824
  • 17
  • 99
  • 186
J. Doe
  • 441
  • 1
  • 4
  • 13
  • Possible duplicate of [Building multiple binaries within one Eclipse project](https://stackoverflow.com/questions/2424795/building-multiple-binaries-within-one-eclipse-project) – Mohammad Zain Abbas Sep 18 '18 at 06:37
  • No, that's not it! You didn't read my question carefully. That answer is to produce multiple binaries. I want to make a single binary from multiple source files. – J. Doe Sep 18 '18 at 06:50
  • [This might provide you what you are looking for.](https://stackoverflow.com/q/513697/6390175) or [this](https://stackoverflow.com/a/26830341/6390175) *let me know if it resolves your issue.* – Mohammad Zain Abbas Sep 18 '18 at 06:58
  • All the source files are found under the `src` folder as seen in the build output above. They build fine, but the process is incremental and they all get linked together in the final step. I am looking to for a way to build them all in a single command, as per question. – J. Doe Sep 18 '18 at 07:02
  • Have you considered using cmake ?? – Mohammad Zain Abbas Sep 18 '18 at 07:21
  • Never had any experience, but I will be glad to get some pointers for my problem. – J. Doe Sep 18 '18 at 07:23

1 Answers1

1

Try using CMake As per my understanding of your question, you would need to add your source files into CMakeList.txt and then run it. You can make use of this tutorial in doing so.

Mohammad Zain Abbas
  • 728
  • 1
  • 11
  • 24