Thread: Problems using/creating a shared library

  1. #1
    Registered User
    Join Date
    Dec 2007
    Location
    Germany
    Posts
    30

    Problems using/creating a shared library

    Hello,
    recently i tried to compile a program using a library i had created following a short instructed tutorial - without success.
    To get the library from the file special.cpp i had used the following two commands:
    Code:
    g++ -fPIC -c special.cpp          
    g++ -shared -Wl,-soname,libspecial.so.1 -o libspecial.so.1.0 special.o
    Afterwards i copied libspecial.so and libspecial.so.1 to $MYLIB/lib/ ($MYLIB is just a directory somewhere under my /home/"username"/ directory) and a header with declarations (special.h) to $MYLIB/lib/ .
    After invoking the compiler
    Code:
    g++-4.2 -Wall -g -o lib lib.cpp -I$MYLIB/include -L$MYLIB/lib -lspecial
    i got a nice little error, complaining my library would not exist:
    Code:
    /usr/bin/ld: cannot find -lspecial
    collect2: ld returned 1 exit status
    What went wrong?

    By the way, this is my third approach to post this. I might be a bit confused, as i hit the back button of my browser two times in order to correct a mistake - after being forced to login again, i realized this is the wrong procedure to correct a misspelled word :P.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The linker searches for libspecial.so. It won't find libspecial.so.1.0. You need to symlink the versioned name to the unversioned name:
    Code:
    ln -s libspecial.so.1.0 libspecial.so
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Dec 2007
    Location
    Germany
    Posts
    30
    Great thanks for your answer, now it works all fine .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's an import library?
    By chiefmonkey in forum C++ Programming
    Replies: 1
    Last Post: 06-19-2009, 05:00 PM
  2. Need help with audio library on DOS...
    By Marton79 in forum C Programming
    Replies: 10
    Last Post: 08-25-2006, 12:32 AM
  3. Problem with custom shared library
    By soothsayer in forum C Programming
    Replies: 3
    Last Post: 05-24-2006, 12:48 PM
  4. wxWidgets loading shared library problem
    By BobS0327 in forum Linux Programming
    Replies: 1
    Last Post: 05-10-2006, 07:23 PM
  5. shared libraries
    By Raven Arkadon in forum C++ Programming
    Replies: 5
    Last Post: 06-27-2005, 07:11 AM