在Eclipse下运行make C ++项目 [英] Running make for a C++ project under Eclipse

查看:656
本文介绍了在Eclipse下运行make C ++项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ubuntu 10.10下开发一个C ++应用程序,使用g ++和automake。对于这个程序,我有两个cpp文件(main.cpp和forward.cpp,后一个是一个测试类),和forward.h;我还有以下makefile:

  main:\ 
forward.o
g ++ -fPIC - g -Wall -D_REENTRANT -fno-exceptions -I / usr / local / Aria / include / -L / usr / local / Aria / lib -lAria -lpthread -ldl -lrt \
-o simple_controller \
main.cpp \
forward.o

%.o:%.cpp
g ++ -c -g -Wall -D_REENTRANT -fno-exceptions -I / usr / local / Aria / include / $< -o $ @

clean:
rm -fv * .o
rm -fv * / *。o

当我将所有这四个文件复制到同一目录并从命令行(bash)调用make时,就会调用g ++并正确编译我的程序。 / p>

好的,现在我想在Eclipse下实现同样的功能。所以我在Eclipse下创建了一个新的非托管C ++项目,以便我可以提供自己的makefile(与上面列出的相同)。不幸的是,当我现在使用Eclipse下的Build all选项时,我可以看到以下控制台输出:

  make 
make:***没有规则,使目标`forward.o','main'需要。停止。

由于我是Linux下的C ++开发的新手,使用g ++和makefiles,问题。我认为正确编译我的应用程序所需的一切都写在makefile中,因为它在命令行中完美地工作。但是它似乎我不能复制相同的makefile 1:1到我的Eclipse项目。



任何想法我在这里丢失了?

提前感谢

$ p

解决方案

好的,我发现现在的问题 - Eclipse把makefile放到另一个目录src 所有源代码文件所在的文件夹。所以make没有找到编译所需的.cpp和.h文件。现在我的结果是这样:

  ... 
forward.o:../src/forward .cpp ../src/forward.h
...

告诉它,它也应该查看文件夹../src即使没有明确陈述?


I am developing a C++ application under Ubuntu 10.10, using g++ and automake. For this program I have two cpp files (main.cpp and forward.cpp, the latter one is a test class), and forward.h; I also have the following makefile:

main: \
forward.o
    g++ -fPIC -g -Wall -D_REENTRANT  -fno-exceptions  -I/usr/local/Aria/include/ -L/usr/local/Aria/lib -lAria -lpthread -ldl -lrt \
    -o simple_controller \
    main.cpp \
    forward.o

%.o : %.cpp
    g++ -c -g -Wall -D_REENTRANT -fno-exceptions  -I/usr/local/Aria/include/ $< -o $@

clean:
    rm -fv *.o
    rm -fv */*.o

When I copy all those four files into the same directory and call "make" from command line (bash) then g++ is called and my program will be compiled correctly.

Ok, now I wanted to achieve the same under Eclipse. So I created a new unmanaged C++ project under Eclipse, so that I can provide my own makefile (the same as listed above). Unfortunately, when I now use the "Build all" option under Eclipse I can see the following console output:

make 
make: *** No rule to make target `forward.o', needed by `main'.  Stop.

Since I am new to C++ development under Linux, using g++ and makefiles, I do not really understand the problem. I thought that everything that is needed to compile my application correctly is written in the makefile, as it works perfectly from the command line. But it seems I cannot copy the same makefile 1:1 into my Eclipse project.

Any ideas what I am missing here?
Thanks in advance for your help!

解决方案

Ok, I found the problem now -- Eclipse is putting the makefile into another directory than the "src" folder where all source code files are located. So make did not find the .cpp and .h files needed for compilation. Now I ended up in something like this:

...
forward.o : ../src/forward.cpp ../src/forward.h
...

Is there any way to tell make that it should also look into the folder ../src even when not explicitely stated?

这篇关于在Eclipse下运行make C ++项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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