Results 1 to 3 of 3

Thread: How to make .so's with g++?

  1. #1

    How to make .so's with g++?

    How does one create a dynamic link library in Linux using g++? I searched Google, and I came up with these instructions:

      gcc -g -fPIC -c module1.c
      gcc -g module1.o -shared -Wl,-soname, -o
    I changed "gcc" to "g++" and ".c" to ".cc". I replaced "something" and "module1" with my library name, "gvector". It created the file I wasn't sure where to put it, so I put it in "/usr/local/lib". I added that directory to to my and ran 'ldconfig' to update my dynamic libraries.

    To link against the program, I typed:

    g++ -lgvector

    I got this error:

    /usr/bin/ld: cannot find -lgvector
    collect2: ld returned 1 exit status

    So, I scrounged around in g++'s man page, and found that '-L' should tell it what directory to look in. I tried putting "-L/usr/local/lib" before and after the '-lgvector' switch. Same error.

    I scrounged around in g++'s man page some more. That brought me to the "-shared" switch. I tried adding "-shared" at the end of the switch list, and still got the same error. I then tried it in different positions throughout the list, and still go the same error.

    Can someone point me to more helpful documentation, or point out my mistake? Thanks!

  2. #2
    redhead's Avatar
    Join Date
    Jun 2001
    Copenhagen, Denmark

    Re:How to make .so's with g++?

    How about libtool ?
    # libtool -mode=compile gcc module1.c
    # libtool -mode=link gcc module1.lo -o

    Saves the need for guessing the flags needed.

    Once you try and link to it, the '-L' flag should be the thing to use.
    You might need a '-I' flag too, if you're not givin the direct path to your header file.

  3. #3

    Re:How to make .so's with g++?

    Thanks! Everything's working now!

    I'd heard mention of something called 'libtool' that made libraries, but I couldn't find a man page for it (and hadn't thought to simply type 'libtool --help'). Thanks again!

Similar Threads

  1. How i make shortcute
    By vadhavane_anil in forum Linux - Hardware, Networking & Security
    Replies: 2
    Last Post: 04-07-2006, 03:50 AM
  2. This'll make you laugh (or cry)
    By SwampDonkey in forum Linux - Software, Applications & Programming
    Replies: 4
    Last Post: 10-24-2002, 09:02 PM
  3. First running of Make
    By PatC in forum Redhat / Fedora
    Replies: 1
    Last Post: 06-25-2002, 03:35 PM
  4. does this make sence to you?
    By boblucci in forum General Chat
    Replies: 23
    Last Post: 02-27-2002, 06:44 PM
  5. Help - I need to make a calculator
    By ph34r in forum Linux - Software, Applications & Programming
    Replies: 2
    Last Post: 12-07-2001, 11:12 AM


Posting Permissions

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