General Linking question. - Aix

This is a discussion on General Linking question. - Aix ; Lets say I created a shared library (libmyFile1.so) with a single function myFunc1 and want to link it into a newly created application (App1). The file libmyFile1.so is located in the /usr/source/lib/ directory. Scenario 1: ------------------ If I do the ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: General Linking question.

  1. General Linking question.

    Lets say I created a shared library (libmyFile1.so) with a single function
    myFunc1 and want to link it into a newly created application (App1).
    The file libmyFile1.so is located in the /usr/source/lib/ directory.

    Scenario 1:
    ------------------
    If I do the following, the application links great and the executable is
    built.
    xlc -o App1 App1.o -L/usr/source/lib/ -lmyFile1


    Scenario 2:
    ------------------
    If I do the following, the application also links great and the executable
    is built, BUT I also have to include another file (myFileexp.o) that
    contains a list of the functions that already exist in the libmyFile1.so.
    xlc -o App1 App1.o -L/usr/source/lib/libmyFile1.so ./myFileexp.o

    Questions:
    --------------
    What is the difference between these two linking commands?
    What is the advantage and disadvantage one scenario has over the other?



  2. Re: General Linking question.

    On May 16, 12:16 am, "JNLSeb" wrote:
    > Lets say I created a shared library (libmyFile1.so) with a single function
    > myFunc1 and want to link it into a newly created application (App1).
    > The file libmyFile1.so is located in the /usr/source/lib/ directory.
    >
    > Scenario 1:
    > ------------------
    > If I do the following, the application links great and the executable is
    > built.
    > xlc -o App1 App1.o -L/usr/source/lib/ -lmyFile1
    >
    > Scenario 2:
    > ------------------
    > If I do the following, the application also links great and the executable
    > is built, BUT I also have to include another file (myFileexp.o) that
    > contains a list of the functions that already exist in the libmyFile1.so.
    > xlc -o App1 App1.o -L/usr/source/lib/libmyFile1.so ./myFileexp.o
    >
    > Questions:
    > --------------
    > What is the difference between these two linking commands?
    > What is the advantage and disadvantage one scenario has over the other?


    Start with the fact that xlc is not the linking command - ld is the
    linker. Use xlc -v to see what commands are actually being called and
    then use "man ld" to look at the differences.

  3. Re: General Linking question.

    On 2008-05-15, JNLSeb wrote:
    > Lets say I created a shared library (libmyFile1.so) with a single function
    > myFunc1 and want to link it into a newly created application (App1).
    > The file libmyFile1.so is located in the /usr/source/lib/ directory.
    >
    > Scenario 1:
    > ------------------
    > If I do the following, the application links great and the executable is
    > built.
    > xlc -o App1 App1.o -L/usr/source/lib/ -lmyFile1
    >
    >
    > Scenario 2:
    > ------------------
    > If I do the following, the application also links great and the executable
    > is built, BUT I also have to include another file (myFileexp.o) that
    > contains a list of the functions that already exist in the libmyFile1.so.
    > xlc -o App1 App1.o -L/usr/source/lib/libmyFile1.so ./myFileexp.o
    >
    > Questions:
    > --------------
    > What is the difference between these two linking commands?


    In the first one, the -lmyFile1 option causes the linker to include
    libmyFile1.so in the files being linked. The -L/usr/source/lib/ option
    includes that directory in the once searched for libmyFiles.so.

    The executable created by the linker contains the information that the
    executable uses a shared object in libmyFile.so and that
    /usr/source/lib/ is to be included in the directories to be searched for
    shared libraries when the program is loaded.

    In the second one, the file ./myFileexp.o file contains the information
    that myFunc1 is exported from a shared object. The contents of
    myFileexp.o (and possibly the -L option) provided enough information
    to the linker to created an executable with enough information to find
    the shared object when the executable is loaded.

    > What is the advantage and disadvantage one scenario has over the other?


    The advantage of the first approach is that it is simplier. You tell
    the linker the name of the shared library and the directory where it
    is (at link time and where it will be at execution time). The
    information about what the shared object exports was put in the shared
    object when it was built.

    The advantage of the second approach is flexibility. You can export
    different symbols by changing the contents of myFileexp.o without
    having to rebuild the shared object. If there is enough information
    in myFileexp.o, you don't need the -L option.

    It is generally better to use a simplier approach.

  4. Re: General Linking question.

    JNLSeb schrieb:
    > Lets say I created a shared library (libmyFile1.so) with a single function
    > myFunc1 and want to link it into a newly created application (App1).
    > The file libmyFile1.so is located in the /usr/source/lib/ directory.
    >
    > Scenario 1:
    > ------------------
    > If I do the following, the application links great and the executable is
    > built.
    > xlc -o App1 App1.o -L/usr/source/lib/ -lmyFile1
    >
    >
    > Scenario 2:
    > ------------------
    > If I do the following, the application also links great and the executable
    > is built, BUT I also have to include another file (myFileexp.o) that
    > contains a list of the functions that already exist in the libmyFile1.so.
    > xlc -o App1 App1.o -L/usr/source/lib/libmyFile1.so ./myFileexp.o
    >
    > Questions:
    > --------------
    > What is the difference between these two linking commands?
    > What is the advantage and disadvantage one scenario has over the other?
    >
    >


    Is /usr/source/lib/libmyFile1.so a diectory? I guess not. See the
    ld man page:
    -L Directory Adds Directory to the list of search directories used for
    finding libraries designated by the -l (lowercase letter
    L) flag. The list of directories, including the standard
    library directories, is also recorded in the output
    object file loader section for use by the system loader
    unless you use the -blibpath, -bnolibpath, or -bsvr4
    option. You can repeat this flag.

  5. Re: General Linking question.

    JNLSeb wrote:
    > Questions:
    > --------------
    > What is the difference between these two linking commands?
    > What is the advantage and disadvantage one scenario has over the other?


    The 2nd might was well not even have the -L option. As has been stated
    -L (in that example) doesn't specify a directory. Therefore, this is a
    usage error.

    Ignoring that, either mechanism is fine. AIX allows one to use either a
    shared module directly, or an import list, and the two are equivalent.
    The latter can be helpful when the dependent module isn't available
    (yet) in its final form.

    And for the record, your import list (myFileexp.o) should be specified
    using -bI:, although naming it directly can accomplish certain goals.

+ Reply to Thread