Shared Library

This is a discussion on Shared Library within the Linux Programming forums, part of the Platform Specific Boards category; Can someone explain how to compile source to be a shared library?...

  1. #1

    Exclamation Shared Library

    Can someone explain how to compile source to be a shared library?

  2. #2


    Yeh all I could find was this

    Produce a shared object which can then be linked
    with other objects to form an executable. Only a
    few systems support this option.

    It didnt really tell me much, I you do know how to do it could you please help?

  3. #3
    I should mention I'm new to C++, I'm trying to do it so I can use C code with my java programs.

  4. #4
    Registered User rohit's Avatar
    Join Date
    Feb 2002
    say you have two files

    main.c and lib.c

    you will make a.out from main.c and from lib.c

    here it goes

    cc -c -o libmylib.o lib.c -fPIC

    cc -shared --wall,--soname,"" -o libmylib.o

    copy your to /usr/lib

    cd to /usr/lib

    create a link and point to

    ldconfig and next time when your compile use "-lmylib"


  5. #5


    Thanx for the help

    Couldnt get it to work but I think it is the Java Native Interface that is stuffed up.


  6. #6
    You might want to ask where the control for linked libraries are maintained. They are most probably maintained on the kernel side (except not in a virtual machine where the kernel is emulated on the user side). My guess is that you will have to perform system calls, or at least your compiler will have to do that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. shared library for QNX
    By ReeV in forum C Programming
    Replies: 3
    Last Post: 05-06-2009, 11:58 AM
  2. Shared library design problem
    By p1r0 in forum C++ Programming
    Replies: 9
    Last Post: 03-23-2009, 01:36 PM
  3. Global variable in shared library
    By krock923 in forum C Programming
    Replies: 5
    Last Post: 01-11-2008, 04:56 PM
  4. Problem calling external method from within a shared library
    By Major Tom in forum C++ Programming
    Replies: 0
    Last Post: 04-21-2007, 10:14 AM
  5. Problem with custom shared library
    By soothsayer in forum C Programming
    Replies: 3
    Last Post: 05-24-2006, 01:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21