0
votes

I'm using linux and I have downloaded a tarball of the soem1.3.0 library that I want to use. I have compiled the library and now I would like to use it. Problem is, I don't know how to do this.

I have a folder called "Project" and in this folder I have a subfolder containing the compiled library (this subfolder contains more folders containing .a files and header and source files) called "Project/SOEM1.3.0". The project folder also has my main function source file, "Project/main.cpp". When I try to compile this main.cpp, the compiler (g++) says that the header files I'm trying to include are unknown.

I guess I have to tell the compiler where to find the library, but how do I do this? I tried copying the entire SOEM1.3.0 folder to /usr/lib, assuming my compiler would be able to find it but this didn't work. Can anybody tell me what to do?

Update: I have been able to include the headers by using "-I path/to/headers". But now the compiler/linker is complaining it cannot find the functions described in the header files. I tried using "-L path/to/libsoem.a -l soem -I path/to/headers" but without result. Any suggestions? Just to be clear, the libraries are called libsoem.a, libosal.a and liboshw.a, and the command i'm trying:

gcc -L SOEM1.3.0/lib/linux -l soem -l osal -l oshw -I SOEM1.3.0/soem -I SOEM1.3.0/osal
-I SOEM1.3.0/oshw/linux -o test main.cpp

1
There should be a file called configure which generates the correct make environment. Then run make.suspectus

1 Answers

2
votes

To tell gcc where to look for the headers during compilation use the -I option (lib has nothing to do with the headers, and no libraries are needed for compilation, i.e. when you use the -c option).

You'll need to tell gcc for the link stage, e.g. when you create an executable with -o name, which libraries to use and where the libraries are. For demanding a certain library use the -l option: for libmath you would specify -lmath; accordingly with other lib* libraries. If those libraries are in a non-standard directory you use the -L option to tell that to gcc.; or you just put them in one of the system's normal lib directories, either manually or via make install.

Edit: I forgot to mention the unintuitive but logical requirement that libraries given to the linker with -l must appear after the library, object or source files which depend on them, i.e. usually in the end. The linker just cherry-picks the definitions needed at that point from a library, it (luckily) doesn't lump everything together.

Order between libraries is also significant, if any of them have unresolved dependencies.