Developing shared libraries with Eclipse CDT

Consider the following not so uncommon scenario: you have a shared library project in Eclipse and an executable project which uses the shared library.

I found that you have to do some additional things for building, running and debugging the executable project in Eclipse (note that I’m doing this on Linux using CDT 4.0.3):

Define your shared library’s project as a reference for your application. In order to do so open the project properties of the executable project, go to project references and select the shared library project (where in my case “shared” is also the name of the shared library).

In the project settings of your executable project, add the shared library to the linker settings, as shown in the following screenshot:

Bear in mind that the library search path must be adjusted every time when switching between Debug and Release versions.

In the project settings of your executable project, add the working directory of your shared library project to the compiler include path, as shown in this screenshot:

Now you should be able to compile your application, but in order to run it from within Eclipse, there’s a last step that needs to be done:

In the run dialog (top menu Run -> Open Run Dialog), define the LD_LIBRARY_PATH variable as ${workspace_loc}/shared/Debug/, as shown inthe following screenshot.

Again, this needs to be adjusted when switching between Debug and Release versions.

All this is very tedious stuff, so hopefully this will be a bit improved in the upcoming CDT releases.

15 thoughts on “Developing shared libraries with Eclipse CDT”

  1. good lord – i really hope you figured out that you don’t have to change all these settings every time you switch between debug & release builds.

    just have a look at the screenshots you posted – right at the top of the page you can choose the configuration – in your case debug is selected.

    that’s the case with a lot of dialogs.

    by the way – there are also different configurations for debug and run settings.

    have fun!

  2. Thanks for the post! Got my project to compile and link as expected.

    However, I am having an issue with your last step: Running the executable project.

    I get the following error:
    /home/mark/workspace2/GenTester/Debug/GenTester: error while loading shared libraries: libGen.so: cannot open shared object file: No such file or directory

    When I click the Run drop down menu there is no “Open Run Dialog” so I can’t seem to set the LD_LIBRARY_PATH.

    Any ideas?

    eclipe 3.4.1
    CDT 5.0.1

    Thanks!
    Mark

  3. Hi Dirk,

    I am using Eclipse CDT for some shared library stuff. I was wondering on how one can debug an application, that links with one of the shared libraries.

    It would be truly wonderful if one could specify shared library source path, and gdb allows breakpoints on the shared library code.

    What are your thoughts on this? I have been searching through Eclipse menus but am having a hard time finding what I want?

    Thanks,
    Karan

  4. By the title of this post, I thougth you were going to explain how to set up a project for generating a shared library with eclipse.

    Is there any chance you can such as post? I’m totally unfamiliar with Eclipse.

    Thanks.

  5. I would like to know how I can use this instructions to link my shared library ( not static libary). I tried to follow this steps but how can i have verbose mode, so that i know where it is trying to include and failing.

    thanks
    -pro

  6. “${workspace_loc:/share}/{$ConfigName}” allows you to use an “All Configurations” setting for Library search path (works for Debug/Release etc).

  7. i have an Eclipse C Main project and in the same workspace i have 2 other
    projects that generate dlls for this project.

    Even if i follow the instructions on the article, i am not coming to a solution.

    i am getting compile time error – cannot find -lxxxxxx (dll)

    Even when i add those two projects to Project References of the main, then too i get the same error but at runtime.

    i have set LD_LIBRARY_PATH using SystemProperties>Env variable.

    What is really missing?

    Do not understand what to do next

    Thanks in advance,
    Abhi

  8. The missing LD_LIBRARY_PATH to my shared library was the trick. Otherwise my application kept not finding the shared library I had included during debug.

    Thanks you for posting this!

    dlc

Leave a Reply