简体   繁体   English

C ++项目的ECLIPSE makefile-源目录

[英]ECLIPSE makefile for C++ projects — source directory

In Eclipse platform (Windows 10, MinGW toolchain), I'm trying to create a makefile to compile a project with .cpp and .hpp files. 在Eclipse平台(Windows 10,MinGW工具链)中,我试图创建一个makefile来编译带有.cpp和.hpp文件的项目。

To do that, I choose to create a new project: File -> (popup) New Project C/C++ -> C/C++ Project => NEXT -> C++ Managed Build => MakefileProject -> Hello World C++ MakefileProject 为此,我选择创建一个新项目:File->(popup)New Project C / C ++-> C / C ++ Project => NEXT-> C ++ Managed Build => MakefileProject-> Hello World C ++ MakefileProject

This example compiles and links perfectly. 该示例完美地编译和链接。 But I want to move the .cpp file into a src directory, then in the Project Explorer window, over the name of the project, I select to create a "Source Folder", naming it as "src". 但是我想将.cpp文件移动到src目录中,然后在“项目资源管理器”窗口中的项目名称上方,选择创建“源文件夹”,并将其命名为“ src”。 Then I move the .cpp file inside the directory, and try to build the project without success. 然后,我将.cpp文件移动到目录中,并尝试构建项目但未成功。

How must I modify the makefile included with this example? 如何修改此示例中包含的makefile? I've tried everything but without luck. 我已经尝试了一切,但是没有运气。 I get this error: 我收到此错误:

*19:51:33 **** Incremental Build of configuration Default for project CE_SEP **** make all make: *** No rule to make target CE_SEP.o', needed by CE_SEP.exe'. * 19:51:33 ****配置的增量生成项目CE_SEP的默认设置****全部制作:***没有规则来创建目标CE_SEP.o', needed by规则。 Stop* 停止*

Thanks for your support in advance! 预先感谢您的支持!

Stop depending on an IDE. 停止依赖于IDE。 There is an actual "Makefile" that you can go in and edit. 您可以进入并编辑一个实际的“ Makefile”。 You likely just have to modify the path to the source file in the Makefile and/or add another Makefile in the "src" folder. 您可能只需要修改Makefile中源文件的路径和/或在“ src”文件夹中添加另一个Makefile。

If you don't know Makefile syntax, google a brief tutorial. 如果您不了解Makefile语法,请使用Google简要教程。

Or save yourself some time in the long run and just learn CMake which is just a scripting type language to write platform-portable build systems -- it will generate Makefiles, MSVC projects, Xcode projects, Ninja build files, etc. 或者从长远来看节省一些时间,只是学习CMake,它只是一种脚本类型语言,用于编写平台可移植的构建系统-它将生成Makefile,MSVC项目,Xcode项目,Ninja构建文件等。

I have solved it. 我已经解决了 I had written wrongly the name of the file, and I have modified the Makefile adding "src\\" before the name of the object an exe file: 我写错了文件名,并且修改了Makefile在exe文件的对象名前添加“ src \\”:

CXXFLAGS =  -O2 -g -Wall -fmessage-length=0
OBJS =      src\CE.o
LIBS =
TARGET =    src\CE.exe
$(TARGET):  $(OBJS)
    $(CXX) -o $(TARGET) $(OBJS) $(LIBS)
all:    $(TARGET)
clean:
    rm -f $(OBJS) $(TARGET)

But I rather will learn some of CMake as "jonrobm" suggested me. 但是我宁愿按照“ jonrobm”的建议学习一些CMake。 Thank you again! 再次感谢你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM