Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Including source files from a separate C++ project(A simple question about how to include source files from an existing C++ project in Eclipse CDT.)
Including source files from a separate C++ project [message #972738] Mon, 05 November 2012 21:36 Go to next message
Max Spencer is currently offline Max SpencerFriend
Messages: 1
Registered: November 2012
Junior Member
I have a project which uses some functions from OpevCV and it compiles into an executable and works fine. Now I want to have a new 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 at the bottom:

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


index.php/fa/12200/0/

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_ */


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,

Max
Re: Including source files from a separate C++ project [message #985745 is a reply to message #972738] Thu, 15 November 2012 22:28 Go to previous message
MASSIMO MANCA is currently offline MASSIMO MANCAFriend
Messages: 2
Registered: November 2012
Junior Member
I found a solution that for me works but obviously there is a drawback. I use this solution especially to test a project using unit tests or similar tecniques.

Suppose to have a workspace containing the Work project and the WorkTest project, if I need to compile a C file contained in Work I click on File/New/Other then in the popup window I choose General/File then I click on the button Advanced>> (in the bottom part of the window) then I click on "Link to file in the file system" and finally I click on "Browse" button and select the source file to link in WorkTest project.
I know, it is a long procedure but it establishes a link between the project and the source file of another project that may be a viable solution for you.

For me is ok, of course every time you change the linked source file you have to build every project where it is used.

I don't like so much to link source files in this way among different projects, in this situation I prefer a simple Import or better a working copy extracted by a git repository so that I can manage the changes without loosing the history of the original file.
Previous Topic:Tracepoint Support in Juno available?
Next Topic:Inferring include paths and make targets from existing Makefile in Eclipse
Goto Forum:
  


Current Time: Thu Mar 28 22:37:08 GMT 2024

Powered by FUDForum. Page generated in 0.03103 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top