linkage problem on linux

Paul Brown
  • Paul Brown

    Paul Brown - 2004-07-14

    i'm trying to build my C library on linux using cpptasks

    i depend on a library called

    my stuff compiles fine, when i come to link, the linker fails to find

    i've put that exact library in several different places just to try and get things working quickly ...i've put it in '/lib', '/usr/lib' and a local directory. all of these directories are on LD_LIBRARY_PATH

    i've also used 'libset' inside <cc> to put the library on the path.

    i'm fairly new to building c libraries on unix...i got it working easily on Windows, which is where i spend most time coding. so i may be misunderstanding the linkage model on unix

    the error i'm seeing:

        [echo] Building native library in debug mode
        [echo] The operating system is Unix-like, using gcc
    Suspicious library name ending with ".so":
    Suspicious library name starting with "lib":
    Suspicious library name ending with ".so":
    Suspicious library name starting with "lib":
    Suspicious library name ending with ".so":
    Suspicious library name starting with "lib":
    Suspicious library name ending with ".so":
    Suspicious library name starting with "lib":
        [cc] Starting dependency analysis for 39 files.
        [cc] 39 files are up to date.
        [cc] 0 files to be recompiled from dependency analysis.
        [cc] 0 total files to be compiled.
        [cc] Starting link
        [cc] [ERROR] /usr/bin/ld: cannot find
        [cc] [ERROR] collect2: ld returned 1 exit status

    File...... file:/home/paul/wmdcc-dev/wmdcc-maven/
    Element... cc
    Line...... 117
    Column.... 28
    gcc failed with return code 1
    Total time: 13 seconds
    Finished at: Wed Jul 14 08:21:42 BST 2004

    [root@test-linux-1 wmdcc-maven]#

    here's my (not very tidy!) build script ... the relevant section:

            <linker name="${cc}">
               <linkerarg value="${linkerargs}" location="mid"/>
               <libset libs="${linkerlibs}"/>
               <libset libs="/lib/libglib-2.0"/>
               <fileset dir="/home/paul/wmdcc-dev/wmdcc-maven/lib_g" includes="${linkerlibs}"/>

    as you can see, i've tried a few things. hope they dont conflict. here's how i set up ${linkerlibs}:

    <j:set var="linkerlibs" value=",,,"

    i have tried prefixing these library names with full paths, and i've also tried dropping the '.so'. didnt help.

    lastly, here's how i set up my build script to put stuff on the LD_LIBRARY_PATH:


    as you can see, i'm grasping at straws at the minute and would appreciate any help offered.


    • saber850

      saber850 - 2004-07-14

      A few things:

      1.  Unlike Windows, Unix/Linux has separate methods of locating libraries during linking and running.  LD_LIBRARY_PATH (LIBPATH on AIX) is used for runtime; it has no bearing during linking.
      To link a library, it should be specified during the operation.  With GCC, you normally specify a path the the lib via the -L flag, and then specify the library with the -l flag.

      2.  LD (the linker) assumes a prefix of 'lib' and a suffix if '.so' or '.a' (in that order) for each library specified.  Thus, to link w/ a library /usr/lib/, the line is typically:
         gcc {output stuff, etc here} -L/usr/lib -lfoo

      3.  Here is a sample config to link in cpptask:
        <syslibset dir="/usr/lib" libs="foo"/>

      Nick G.

      • clem

        clem - 2004-07-14

        This brings up a subject that I've been having problems with myself. 

        What does one do with libraries that have unconventional names?  I'm currently wrestling with getting the infozip unzip.a library to link with <cc>.  Any ideas?

        • saber850

          saber850 - 2004-07-14

          Did you try renaming the file to libunzip.a?
          Another method is to list the library w/ the absolute path.  The disadvantage of this is that the resulting lib/exe will require the lib in that particular location.  But this only applies to shared objs, archives will get linked in statically.
          So the line would be something like:
          gcc -l/your/path/to/the/file/libunzip.a

          Notice no -L flag.

          BTW, the aforementioned doesn't apply to Windows--you can't simply rename DLLs.

    • Curt Arnold

      Curt Arnold - 2004-07-14

      The libset and syslibset adapt to the linker's conventions for library names.  The value for libs should not contain any linker specific file prefixes (lib) or suffixes (.so, .lib, .a).

      For example, to link with kernel32 with the Microsoft linker, the command line would look something like:

      link .... kernel32.lib ....

      and there would be a file kernel32.lib somewhere.

      If you were linking the same file gcc using Cygwin, the command would look like:

      ld -l kernel32

      ld would look for a file named, libkernel32.a, etc.

      If you use <syslibset libs="kernel32"/>, cpptasks will try to link kernel32.lib when using MS linkers and use -l kernel32 with unix style linkers.

      If you specify <syslibset libs=""/>, then cpptasks will link using MS linkers and use -l using unix style linkers that will try to find files named  In most cases, libnames that start with lib or end with .so indicate a misunderstanding of <syslibset/>, cpptasks prints the warnings you saw.

    • Paul Brown

      Paul Brown - 2004-07-15

      thanks fellas

      it's linking now!!

      thank god for this list!


Log in to post a comment.