[RESOLVED] Dynamic/static linking question
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: [RESOLVED] Dynamic/static linking question

  1. #1
    Join Date
    Feb 2005
    Location
    Denver
    Posts
    345

    [RESOLVED] Dynamic/static linking question

    On a linux system, is it possible to link with both static and dynamic libraries (different libraries, of course) at the same time? I used to do this on a Solaris platform but have been unsuccessful on linux. I can build an executable using all dynamic libraries, or with all static libraries, but I can't mix them up. Is this strictly unique to Solaris? If it is possible, can someone please show me what combination of compiler/linker flags are necessary, and how to use them. Thanks.

    Note: This is with the gnu g++ compiler.

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,888

    Re: Dynamic/static linking question

    If you simply specify the name of the library file on the command line (ending in .a for static or .so for dynamic), the corresponding library will be linked.

  3. #3
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Re: Dynamic/static linking question

    g++ o my.c my( executable ) -lcairo
    where cairo the the lib you are trying to link to , I do not know if there a a solaris build for Netbeans m if there is then download the C++ edition , Netbeans automates a lot of building process.

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,888

    Re: Dynamic/static linking question

    If you use the -l method of linking, then the compiler will look for either a .a or a .so with the proper name and you have little control over which it chooses. Specifying the library name entirely guarantees which one is used.

  5. #5
    Join Date
    Feb 2005
    Location
    Denver
    Posts
    345

    Re: Dynamic/static linking question

    Quote Originally Posted by Lindley View Post
    If you simply specify the name of the library file on the command line (ending in .a for static or .so for dynamic), the corresponding library will be linked.
    Sorry for not getting back to you sooner on this (just been extremely busy lately). Anyway, thanks for the info, it worked perfect. I didn't realize you could directly specify the library name in the compilation/link command. I kept trying to use combinations of the -static and -shared options, along with the -l option. Thanks again!

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center