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
    Kinasz
    Guest

    Exclamation Shared Library

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

  2. #2
    Kinasz
    Guest

    Post

    Yeh all I could find was this

    -shared
    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
    Kinasz
    Guest
    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
    Posts
    69
    say you have two files

    main.c and lib.c

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

    here it goes

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

    cc -shared --wall,--soname,"mylib.so.0" -o libmylib.so libmylib.o

    copy your libmylib.so to /usr/lib

    cd to /usr/lib

    create a link mylib.so.0 and point to libmylib.so.o

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

    cheers

  5. #5
    Kinasz
    Guest

    Wink

    Thanx for the help

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

    -Kinasz

  6. #6
    Captain
    Guest
    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, 10:58 AM
  2. Shared library design problem
    By p1r0 in forum C++ Programming
    Replies: 9
    Last Post: 03-23-2009, 12:36 PM
  3. Global variable in shared library
    By krock923 in forum C Programming
    Replies: 5
    Last Post: 01-11-2008, 03: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, 09:14 AM
  5. Problem with custom shared library
    By soothsayer in forum C Programming
    Replies: 3
    Last Post: 05-24-2006, 12:48 PM

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