如何在Eclipse C++中使用现有的Makefile?

11

我是一个新手,遇到了一个问题! 我需要使用一个C++代码,并且不知道如何在Eclipse中导入和编译它(我已经成功通过命令行编译了它)。 这个代码有一个特定的结构,并且组织方式如下:

repos____lib____configure (execute the configure file inside the libraries folders)
                  I           I___makefile (execute the make file inside the libraries folders,
                                                        requires make/make.def)
      I           I___ib1____.cpp
      I           I            I____.h
      I           ...          I____configure (it requires make/configure_lib and
                                                              make/configure_includes
      I           ...          I____makefile (generated by configure)
      I           I___lib2___....
      i           I___.......
      I           I___libn____.cpp
      i                        I____.h
      i                        I____configure
      i                        I____makefile (generated by configure)
      I
      I___make(folder)__bashrc (are set the some environment variables)
      I                               I__configure_bin
      I                               I__configure_includes
      I                               I__configure_lib
      I                               I__make.def (are set all the include path and library path used
      I                                                         in the configure file)
      I___application__main.cpp
                                   I__configure
                                   I__makefile(generated by the configure file)

为了确保你理解我的问题...(确保...:))

第一个配置文件是:

cd lib1; ./configure
cd ../lib2; ./configure
.....
....
cd ../libn; ./configure
cd

第一个 Makefile 文件是:

include /media/Dati/WORKHOME/repos/make/make.def

这是整个库的Makefile文件

lib:
    make -C lib1
    make -C lib2
    make -C libn

配置文件示例(位于lib1内部的文件):

   #!/usr/bin/perl

$INC = '$(OPENCVINC) $(FLTKINC) $(DC1394V2INC)';  ##<-DEFINED IN /make.def
$LIB = '$(OPENCVLIB) $(FLTKLIB) $(DC1394V2LIB)';      #####################

#-------------------------------------------------------------------------------

require '/media/Dati/WORKHOME/repos/make/configure_lib';
print "Created Makefile.\n";

# this will create a include file for the whole directory, 
# using the template <dirname>.h.templ
require '/media/Dati/WORKHOME/repos/make/configure_includes';
print "Created $libname.h\n";

在没有使用Eclipse的情况下,简单地编译它:

  1. 进入lib文件夹,键入./configure
  2. 键入make
  3. 进入应用程序文件夹
  4. 键入./configure
  5. 键入make
  6. 运行程序

我的问题是......在Eclipse中怎么做?我已经使用“导入/导入现有代码”将这三个项目作为Makefile项目导入了,但现在我不知道如何编译它。你能帮我吗?这很重要!

非常感谢 gabriele


4
对于这个6分声望的人来说,这是一个格式良好的问题,我给它点赞。+1 - Kiril Kirov
1个回答

1

使用“将现有代码导入为makefile项目”是正确的做法。 现在Eclipse知道它需要调用make并使用您的makefile。但是,您的构建过程不仅由make驱动。

一种解决方案是编写一个makefile来调用所有构建步骤。类似于:

all:
    cd dir1 && ./configure && make
    cd dir2 && ./configure && make 
    etc.

我的看法

编辑:

我目前没有安装eclipse,所以无法为您提供详细步骤...对不起


@gabriele:这是正确的方式。StackOverflow不同于其他论坛,因为它强调良好书写的问题和答案。最好的方式是评论问题/答案并在必要时编辑它们。这样你就能得到书写良好并且正确的答案,而不是很多评论/回复/答案... - neuro

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接