如何在Eclipse中一次从多个源文件构建 [英] How to build from multiple source files at once in Eclipse

查看:112
本文介绍了如何在Eclipse中一次从多个源文件构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Eclipse C ++项目,最初具有 first.cpp 。然后添加 second.cpp 并将其链接到原始文件。使用Eclipse构建工具,我得到以下输出:

 制作所有
构建文件:../src/first。 cpp
调用:GCC C ++编译器
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
完成的建筑:../src/first.cpp

生成文件:../ src / second.cpp
调用:GCC C ++编译器
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
完成的建筑: ../src/second.cpp

构建目标:第一个
调用:GCC C ++链接器
g ++ -L / usr / local / lib -o first ./src /first.o ./src/second.o
完成的建筑目标:第一个

如何

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

非常感谢。



== ==================================================



我在问如何从多个二进制文件中制作一个二进制文件。= p ======================

源文件,而不是使用多个源文件构建多个二进制文件

解决方案

尝试使用 CMake
根据我对您问题的理解,您需要将源文件添加到 CMakeList.txt 然后运行它。为此,您可以使用本教程。 / p>

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.

解决方案

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.

这篇关于如何在Eclipse中一次从多个源文件构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆