How to build from multiple source files at once in Eclipse

我的未来我决定 提交于 2019-12-14 03:25:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!