I have a Shared Library wise.so. How I can use it in my programm? Do I need to include headers of that library?
I work with Eclipce under Linux. I have set a path to the library using -L and -l. But my function is not visible in the program.
Could you explain me how does Shared Library work?
Regards.
EDIT:
I get the following error:
int main() {
char* path = "/export/home/pdmazubi3/workspace/proj1/src/pic.jpg";
CEDD_Descriptor::CEDD ced; // undefined reference to `CEDD_Descriptor::CEDD::CEDD[in-charge]()'
ced.execute(path);
}
Header:
class CEDD
{
public:
CEDD(double Th0, double Th1, double Th2, double Th3,bool CompactDescriptor);
CEDD();
~CEDD(void);
double T0;
double T1;
double T2;
double T3;
bool Compact;
double* execute(char* path);
private:
int cedd_segnum; //number of segments
int* cedd_partitionSize; //number of pixels in each segment
};
You need to include the header file in your application and link against it.
Have a look at how to use libraries in shared libraries and Linux howto .
If the header file is not in the same directory as your application (which it usually isn't) then you need to tell compiler where to look for it, you use -I/path/to/include
to include path to include directory that contains the header file.
In linking step you need to point to the library. The general usage is to use -L/path/to/lib
is path to directory containing your library followed by -l<libname>
where <libname>
is the name of library without lib
eg if you have libboost_serialization-d-1_34_1.so
you would use -lboost_serialization-d-1_34_1
Examples:
g++ -I/sw/include -Wall -g -I/usr/local/include/boost-1_36/ -c main.cpp -o main.o
g++ -L/sw/lib -lboost_serialization-d-1_34_1 -o x main.o
Have you also modified the Include path (the -I option) so it knows where to look for the headers for the library? If you haven't done this then the compiler will complain about being unable to find functions/classes/structures/etc.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.