Forum Stats

  • 3,852,452 Users
  • 2,264,105 Discussions
  • 7,905,069 Comments

Discussions

Creating dynamically loadable shared library

807578
807578 Member Posts: 13,959 Green Ribbon
How to I take source code with a simple c function and convert it
to a dynamically loadable shared library (such as .so libraries)?

Comments

  • 807578
    807578 Member Posts: 13,959 Green Ribbon
    To build a dynamic library, compile the source code into object code
    giving the compiler the -KPIC option. This causes the compiler to
    generate "position independant" object files.

    cc -c -KPIC file1.c
    cc -c -KPIC file2.c

    Then link the object files (via the compiler), by using the -G and -o
    options.

    cc -G -o libname.so.1 file1.o file2.o

    The -G option tells the compiler to have the linker create a shared
    library. The -o is followed by the name of the shared library to
    create.

    This creates a shared library called libname.so.1.
This discussion has been closed.