Find the answer to your Linux question:
Results 1 to 4 of 4
Hi I have a c++ project in which I compile a shared library and then link an executable against it. This used to work fine for me so, i have ...
  1. #1
    Just Joined!
    Join Date
    Nov 2009
    Posts
    2

    gnu linker: executable cannot find a versioned shared library

    Hi

    I have a c++ project in which I compile a shared library and then link an executable against it. This used to work fine for me

    so, i have a shared library, let's say "libmylib.so",, created with

    Code:
    g++ -shared -Wl,-soname,libmylib.so -o libmylib.so [other otpions]
    and it is located in /home/user/project/lib/c++

    then i have an executable in [project-path]/cmd/c++ (let's call it "test"), which is linked against this library as
    Code:
    g++ -Wl,-rpath=/home/user/project/lib/c++ -o test -lmylib -L /home/user/project/lib/c++ [other options]
    and this all works fine, ldd shows that the executable is able to locate all libraries and it runs as it is supposed to.

    Recently, I decided to introduce version numbering to my project. So if the version number is 1.2.3 the library linking command now is
    Code:
    g++ -shared -Wl,-soname,libmylib.so.1 -o libmylib.so.1.2.3 [other options]
    followed by
    Code:
    ln -sfv libmylib.so.1.2.3 libmylib.so
    creating a convenience symbolic link. this is all still in /home/user/project/lib/c++

    running the same executable linking command for the "test" executable as above succeeds, but ldd shows that libmylib.so.1 cannot be found by the executable.

    I ran readelf on the library, and it shows that the soname field is set correctly to libmylib.so.1. I also ran readelf on the executable and found that rpath is set correctly to /home/user/project/lib/c++.

    I really don't know what to do now. I have had my share of pain when I was working out how the whole dynamic linking system works before, but this is something I cannot understand.

    Any help would be greatly appreciated

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    This is probably knit-picking but is this line correct "libmylib.so -o libmylib.so". Just a posting typo?

    Code:
    g++ -shared -Wl,-soname,libmylib.so -o libmylib.so [other otpions]
    Make mine Arch Linux

  3. #3
    Just Joined!
    Join Date
    Nov 2009
    Posts
    2
    Quote Originally Posted by gerard4143 View Post
    This is probably knit-picking but is this line correct "libmylib.so -o libmylib.so". Just a posting typo?

    Code:
    g++ -shared -Wl,-soname,libmylib.so -o libmylib.so [other otpions]
    I don't think that's a typo, that's how my linking stage always runs. What's wrong with it?

  4. #4
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    A long shot: I notice that you are using
    Code:
    -Wl,-soname,libmylib.so.1
    man ld says that the form for supplying the soname is
    Code:
    -soname=name
    not with a comma, but I have not tried either one personally ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...