简体   繁体   English

Linux中Eclipse C / C ++的Makefile

[英]Makefile for Eclipse C/C++ in Linux

i'm using Eclipse 3.6 for C/C++ for Linux. 我正在使用Eclipse 3.6 for C / C ++ for Linux。 I need to compile existing project with my own working makefile. 我需要使用自己的工作makefile编译现有项目。 This makefile works well from the command line, but when I imported my project into Eclipse and try to use Build, it doesn't work, seems that it try to use makefile automatically created by Eclipse. 这个makefile在命令行上运行良好,但是当我将项目导入Eclipse并尝试使用Build时,它不起作用,似乎它尝试使用Eclipse自动创建的makefile。 I unchecked the switch "Generate Makefile automatically" in Project Properties - C/C++ Build, and instead of many errors got this: "*** commands commence before first target. Stop." 我在“项目属性-C / C ++构建”中取消选中“自动生成Makefile”开关,得到的不是很多错误:“ ***命令在第一个目标之前停止。停止。”

May be this project was not imported correctly into Eclipse? 可能是该项目未正确导入Eclipse吗? I know there is such a thing as "Standard Make project" which will not create makefile automatically but needs my own makefile, but in Eclipse IDE (under File- New- C++ Project) there is no "Standard Make project" options available. 我知道有诸如“ Standard Make project”之类的东西,它不会自动创建makefile,而是需要我自己的makefile,但是在Eclipse IDE中(“ File-New-C ++ Project”下)没有“ Standard Make project”选项可用。 So question is how to point Eclipse to the right makefile for building the imported project? 那么问题是如何将Eclipse指向正确的makefile来构建导入的项目?

I also tried to switch off the "Use default build command" in Project Properties - C/C++ Build and put there in "Build command" line /path_to_project_folder/make, the result is (in Console): Cannot run program "/path_to_project_folder/make": Unknown reason" I would appreciate any suggestions. 我还尝试在项目属性-C / C ++构建中关闭“使用默认构建命令”,并将其放置在“构建命令”行/ path_to_project_folder / make中,结果是(在控制台中):无法运行程序“ / path_to_project_folder /使“:未知原因”,我将不胜感激任何建议。

Don't import. 不要导入。

Instead, create a NEW project using the "Makefile Project from Existing Code" under C/C++. 而是使用C / C ++下的“来自现有代码的Makefile项目”创建一个NEW项目。

Yes, it's somewhat counterintuitive, but it works. 是的,这有点违反直觉,但是可以。

So far the best way to deal with this situation which i found, is to substitute automatically generated by Eclipse makefile (which is stored in Debug directory, created by Eclipse in the project folder) with my own makefile, in which i just include this lines: 到目前为止,我发现处理这种情况的最好方法是用我自己的makefile替换由Eclipse makefile自动生成的文件(存储在Debug目录中,Eclipse在项目文件夹中创建),该文件由我自己的makefile代替。 :

all: 
    cd .. && $(MAKE)

Now when i try to build the project from the Eclipse IDE (with the button) it executes that makefile, which does all the job, and the projects compiles normally. 现在,当我尝试从Eclipse IDE(使用按钮)构建项目时,它将执行该makefile,该文件将完成所有工作,并且项目可以正常编译。

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

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