user101375
user101375

Reputation: 7071

undefined reference to the shared library function

I have implemented a shared library in Linux and try to test it, but I get an error "undefined reference to `CEDD(char*)'".

I use Eclipse with following parameters:

My Code:

Test programm I use for tests:

#include <iostream>
#include <Descriptor.h>

int main() {
    char* path = "/export/home/pdmazubi3/workspace/proj1/src/pic.jpg";
    double * cedd = CEDD(path); /////   <-ERROR!

    std::cout << "!!!Hello World!!!" << cedd[1];
    return 0;

}

Header Descriptor.h:

double* CEDD(char* path);

A part of Descriptor.c with desirable function:

#include "Descriptor.h"
#include "highgui.h"
#include "cv.h"

double* CEDD(char* path)
{
    IplImage* srcImg;
    IplImage* ImageGrid;
...
}

What I am doing wrog? I have raed a lot of articles in the Internet but I didn't found a solution.

undefined reference to `CEDD(char*)' is a compiler or linker error?

Upvotes: 2

Views: 8474

Answers (2)

mweerden
mweerden

Reputation: 14051

It's a linker error (although I don't think it usually includes the 'char*' bit), so it seems that it either cannot find your library or the library does not contain the function. The latter might also mean that it does contain the actual function, but with a different name; make sure both projects a compiled as C and not C++.

Edit: I missed that you program is C++ (which also explains the more detailed linker message). In this case you should add extern "C" (conditionally, so it is only used when using C++) to the declaration of CEDD if the library is in C.

Upvotes: 2

Cătălin Pitiș
Cătălin Pitiș

Reputation: 14341

Are you sure that you linked the object code generated for descriptor.c when building?

Upvotes: 1

Related Questions