问题
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
Thank you so much.
============================================================================
I am asking how to make a single binary from multiple source files, not building multiple binaries with multiple source files.
回答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.
来源:https://stackoverflow.com/questions/52380156/how-to-build-from-multiple-source-files-at-once-in-eclipse