在Eclipse CDT中包括来自另一个C ++项目的源文件 [英] Including source files from another C++ project in Eclipse CDT

查看:126
本文介绍了在Eclipse CDT中包括来自另一个C ++项目的源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Eclipse CDT中有一个C ++项目,该项目使用了OpevCV中的某些功能,并且可以编译为可执行文件并且运行良好。现在,我想要一个新的C ++项目,该项目使用第一个中定义的某些功能。我无法将两者编译并链接在一起。

I have a C++ project in Eclipse CDT which uses some functions from OpevCV and it compiles into an executable and works fine. Now I want to have a new C++ project which uses some of the functions defined in the first one. I can't get the two to compile and link together.

我有 #include ... 在新项目的相关文件中,将旧项目添加到新项目的引用项目中,并在新项目的构建设置中,将旧项目的源文件夹添加为包含文件( -I gcc选项)。

I have #include "..." in the relevant files in the new project, I've added the old project to the referenced projects of the new project and in the build settings of the new project, I've added the source folder of the old project as an include (-I gcc option).

我附上了Eclipse的屏幕截图,以防它有用:

I've attached a screenshot of my Eclipse in case it's helpful:

编译器给出的错误是:


构建目标:OtherProject

调用: GCC C ++链接器

g ++ -o OtherProject ./src/foo.o

./src/foo.o:在函数`main'中:

/home/max/opencvjni/OtherProject/Debug/../src/foo.cpp:13:未定义对threshold()的引用'

collect2:ld返回1退出状态

make:*** [OtherProject]错误1

Building target: OtherProject
Invoking: GCC C++ Linker
g++ -o "OtherProject" ./src/foo.o
./src/foo.o: In function `main':
/home/max/opencvjni/OtherProject/Debug/../src/foo.cpp:13: undefined reference to threshold()'
collect2: ld returned 1 exit status
make: *** [OtherProject] Error 1

以下是屏幕快照其他选项卡中其他文件中的代码:

Here is the code in those other files in the other tabs of the screenshot:

Threshold.cpp

#include <cv.h>
#include <highgui.h>
#include "Threshold.h"

using namespace cv;

int threshold(void) {
   Mat img = imread("/home/max/opencvjni/monalisa.jpg", 0);
   threshold(img, img, 127, 255, THRESH_BINARY);
   imwrite("/home/max/opencvjni/monathresh.jpg", img);
   return 0;
}

int main(void) {
  threshold();
  return 0;
}

Threshold.h

#ifndef THRESHOLD_H_
#define THRESHOLD_H_

int threshold(void);

#endif /* THRESHOLD_H_ */[/code]




  • Eclipse版本:3.7.2

  • CDT版本:8.0.2.201202111925

  • 操作系统:Ubuntu 12.04

  • 感谢您浏览我的帖子,如果没有办法,或者更明智的做法是,请不要犹豫。这么说。

    Thank you for looking at my post, if there is no way to do this, or it is just more sensible to do it another way, please don't hesitate to say so.

    问候

    推荐答案

    我正在寻找一个也可以回答,但先前的答案并不能解决问题。 (尼克的回答很有帮助)。
    您必须定义2件事:

    I was looking for an answer too but the previous answers did not solve the problem. (Nick's answer was helpful). You have to define 2 things:


    1. 转到 Project-> Properties-> C / C ++常规->路径和符号。选择源位置标签,然后单击链接文件夹... ,然后选择要包括的文件夹。

    2. 转到项目->属性-> C / C ++常规->路径和符号。选择包含标签。
      确保在左侧菜单上选择正确的语言(例如: GNU C ++ ),然后单击添加... ,然后选择要包含的文件夹。

    1. Go to Project->Properties->C/C++ general->Paths and Symbols. Select the Source Location tab and click the Link Folder..., Then select the folder you want to include.
    2. Go to Project->Properties->C/C++ general->Paths and Symbols. Select the Includes tab. Make sure you select the correct language on the left menu (for example: GNU C++) and click Add..., Then select the folder you want to include.

    注意:确保有必要,但是当我创建外部项目时,在新项目向导中选择了共享库选项。

    Note: I'm not sure it's necessary but when I created the external project I selected the "Shared Library" option in the new project wizard.

    要确保一切正常,请转到: 项目->属性-> C / C ++构建->设置。选择 GCC C ++链接器,并确保所有选项包含 -L / your_folder_name。
    还要对 GCC C ++编译器重复此操作。

    To make sure you did everything OK, go to : Project->Properties->C/C++ Build->Settings. Select the GCC C++ Linker and make sure that the All options contains "-L/your_folder_name". Repeat this for GCC C++ Compiler also.

    这篇关于在Eclipse CDT中包括来自另一个C ++项目的源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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