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.
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).
I've attached a screenshot of my Eclipse in case it's helpful:
The error given by the compiler is:
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]
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.
Regards
The CDT Project provides a fully functional C and C++ Integrated Development Environment based on the Eclipse platform.
Eclipse is popular for Java project development. It also supports C/C++, PHP, Python, Perl, and other web project developments via extensible plug-ins. Eclipse is cross-platform and runs under Windows, Linux and Mac OS.
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:
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.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.
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.
Go to Project->Properties->C/C++ general->Paths and Symbols. Select the 'Source Location' tab and click the 'Link Folder...' button. You should be able to select the directory containing the project you want to reference. All the source files for that project will be included in your current project. Works for me anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With