ThoughtFlows (Tag: linux)

C++ Shared Libraries with Eclipse CDT on Linux

  1. Create the new C++ "Shared Library". Symbols are exported by default by GCC; no need for declspec as used for MSVC. For more precise control of symbol visibility, consider the lib-symbol-visibility module for GCC 4.0+ (http://www.gnu.org/software/gnulib/manual/html_node/Exported-Symbols-of-Shared-Libraries.html).
  2. In library client's project settings, add entry to compiler include directory listing: "C/C++ Build > Settings > Tool Settings > GCC C++ Compiler > Includes"
  3. Add entry to linker libraries listing: "C/C++ Build > Settings > Tool Settings > GCC C++ Linker > Libraries". Shared libraries in Linux follow the naming convention libXYZ.so, where "XYZ" is the actual name of the shared library. Use the library name, and NOT the full file name, for this entry. (See http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html .)
  4. Add an entry to the linker library search path listing on the same settings pane. This is the directory that contains your shared .so file.
  5. In library client's project settings, Create a reference to the shared library project, so it will be rebuilt as necessary: "C/C++ General > Paths and Symbols > References"
  6. Build the client.
  7. Make sure the library loader can locate the shared library. Permanent libraries should be installed to one of the locations referenced by /etc/ld.so.conf . You may wish to add an entry by including a new file under /etc/ld.so.conf.d . Development libraries can be referenced by exporting LD_LIBRARY_PATH . To diagnose problems, export LD_DEBUG=files .

    Note that other considerations are necessary for permanent libraries, such as versioning and symbolic link creation via ldconfig . See http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html .

By Haw-Bin Chai

Sub Navigation