Find the answer to your Linux question:
Results 1 to 3 of 3
When I try to link my code with a static library (libxxx.a), I encountered problems specifying the path. The following works: Code: gcc -o myexe (path of libxxx.a)/libxxx.a mysrc.c But ...
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    21

    Question linking to static library

    When I try to link my code with a static library (libxxx.a), I encountered problems specifying the path.
    The following works:
    Code:
    gcc -o myexe (path of libxxx.a)/libxxx.a mysrc.c
    But it seems that
    Code:
    gcc -L(path of libxxx.a) -lxxx -o myexe mysrc.c
    doesn't work.
    Does the -L,-l pair only apply in dynamic linking?

  2. #2
    Linux User nalg0rath's Avatar
    Join Date
    Sep 2004
    Location
    Stockholm
    Posts
    303
    Try this:
    Code:
    gcc -static -L(path of libxxx.a) -lxxx -o myexe mysrc.c
    You have to make sure your system supports dynamic linking of course.

  3. #3
    Just Joined!
    Join Date
    Feb 2008
    Posts
    21
    Merci beaucoup!
    But it turns out that without -static it also works. The order of arguments should be changed:
    Code:
    gcc mysrc.c -L(path of libxxx.a) -lxxx -o myexe
    gcc manual says that -L/-l pair takes effect only after a precedent source file.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...