我有一个Eclipse C ++项目,最初有first.cpp
。然后添加second.cpp
并且应该链接到原始文件。使用Eclipse构建工具,我得到了这个输出:
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
如何让Eclipse以这种方式编译?
g++ first.cpp second.cpp -o first
非常感谢。
============================================================================
我问如何从多个源文件制作单个二进制文件,而不是building multiple binaries with multiple source files。
尝试使用CMake根据我对您的问题的理解,您需要将源文件添加到CMakeList.txt
然后运行它。你可以利用this tutorial这样做。