My requirement is to work on some interface .h files. Right now I have .h and .cpp/.cc files in my project.
I need to compile it into shared 64-bit linux compatible library (*.so), using NetBeans/ Eclipse on Linux Fedora.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are compiling a library from the 3 C++ source files called a.cc, b.cc, and c.cc respectively;
Then you install the library using ldconfig, see
you can then compile the program that uses the libary as follows (but be sure to prefix
before the class declarations in the header files included in the source code using the library.)
g++ -o myprog main.cc -lmylib
I have tried these compile options with my own sample code, and have been successful.
Basically What is covered in Shared Libraries applies to C++, just replace gcc with g++.
The theory behind all of this is;
Libraries are loaded dynamically when the program is first loaded, as can be confirmed by doing a system call trace on a running program, e.g.
strace -o trace.txt lswhich will dump a list of the system calls that the program made during execution into a file called trace.txt. At the top of the file you will see that the program (in this casels) had indeed mmapped all the library’s into memory.Since libraries are loaded dynamically, it is unknown at link time where the library code will exist in the program’s virtual address space during run time. Therefore library code must be compiled using position independent code – Hence the
-fpicoption which tells the translation stage to generate assembly code that has been coded with position independent code in mind. If you tellgcc/g++to stop after the translation stage, with the-S(upper case S) option, and then look at resulting ‘.s’ file, once with the-fpicoption, and once without, you will see the difference (i.e. the dynamic code has @GOTPCREL and @PLT, at least on x86_64).The linker, of course must be told to link all the ELF relocatatable object types into executable code suitable for use as a Linux shared library.