Results 1 to 10 of 10

Thread: HOWTO: Create C/C++ libraries in Linux (static and dynamic linking)

  1. #1

    Lightbulb HOWTO: Create C/C++ libraries in Linux (static and dynamic linking)

    Hi people. I've wrote two howtos on my site about C/C++ library programming on Linux. I think this would be useful to many people because many people ask me about it.

    Here are the links, hope you find it useful:

    C/C++ library programming on Linux – Part one: Static libraries

    C/C++ library programming on Linux – Part two: Dynamic libraries

    C/C++ library programming on Linux – Part three: Dynamic libraries using POSIX API

    Long live Ubuntu and Linux!
    Last edited by MarkoCro; July 24th, 2011 at 02:59 AM. Reason: Add the last article about on demand dynamic libraries
    http://www.techytalk.info
    The place of bad english and good Linux content

  2. #2
    Join Date
    Apr 2008
    Location
    Midwest usa
    Beans
    378
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: C/C++ library programming on Linux (Static and dynamic libraries)

    Thanks... poke around your side a bit... Clicked on a few links.. Nice site.. Need to get my c++ homework done at the moment.. But it's some topic of interest.

  3. #3

    Re: C/C++ library programming on Linux (Static and dynamic libraries)

    Quote Originally Posted by Jonas thomas View Post
    Thanks... poke around your side a bit... Clicked on a few links.. Nice site.. Need to get my c++ homework done at the moment.. But it's some topic of interest.
    Thanks Jonas especially for clicking on "the" links, i spend a lot of time writing articles about things other people helped me learn. Then I hope they will do the same for other people and our Linux will go forward. Feel like I need to give something back to the community. If I can help with the homework please let me know
    Last edited by MarkoCro; April 10th, 2011 at 12:39 AM.

  4. #4
    Join Date
    Aug 2007
    Location
    Hastings, NZ
    Beans
    357
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: C/C++ library programming on Linux (Static and dynamic libraries)

    :ks

  5. #5
    Join Date
    Jan 2006
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: C/C++ library programming on Linux (Static and dynamic libraries)

    stickied.

    Critique:
    In the first part, you are defining function prototypes in the "user" code. I would suggest having a library header and loading that instead and having the protection defines in the library header.
    I am infallible, you should know that by now.
    "My favorite language is call STAR. It's extremely concise. It has exactly one verb '*', which does exactly what I want at the moment." --Larry Wall
    (02:15:31 PM) ***TimToady and snake oil go way back...
    42 lines of Perl - SHI - Home Site

  6. #6

    Re: C/C++ library programming on Linux (Static and dynamic libraries)

    Quote Originally Posted by slavik View Post
    stickied.

    Critique:
    In the first part, you are defining function prototypes in the "user" code. I would suggest having a library header and loading that instead and having the protection defines in the library header.
    Yes that would be better approach but I've tried to keep things simple and all in one place. I will add sentence or two about the right way of putting function prototypes in the header file. Thanks slavik.
    Last edited by MarkoCro; April 10th, 2011 at 03:06 PM.
    http://www.techytalk.info
    The place of bad english and good Linux content

  7. #7
    Join Date
    May 2011
    Location
    United States
    Beans
    1
    Distro
    Kubuntu

    Re: HOWTO: Create C/C++ libraries in Linux (static and dynamic linking)

    Hey, thank you for this resources. They're very helpful.

  8. #8
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: HOWTO: Create C/C++ libraries in Linux (static and dynamic linking)

    I wanted to note that there's an alternative to setting LD_LIBRARY_PATH in order to make the linker aware of a library that's not installed in any of the default paths.

    It goes like this, when you're about to link your program to your homebrew library, add the following flags (where DIRECTORY is the path to the library):

    Code:
    -Wl,-rpath,DIRECTORY
    This will record the library's given path in the executable. The only issue with this is that if you relocate the library, the linker won't find it and you'll have to recompile the program. But it may be worth for people that are just learning about library development and don't want to be setting an environment variable everytime neither want to change .bashrc just for this.

    Hope this helps.

    (Source: http://tldp.org/HOWTO/Program-Librar...libraries.html and tested by myself )

    EDIT: Corrected code. $(DIRECTORY) was incorrect for obvious reasons...
    Last edited by nvteighen; June 26th, 2011 at 10:47 AM.

  9. #9
    Join Date
    Sep 2006
    Location
    BC, Canada
    Beans
    347
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: HOWTO: Create C/C++ libraries in Linux (static and dynamic linking)

    I would also like to point out that libtool (http://www.gnu.org/software/libtool/manual/libtool.html) makes creating static and dynamic libraries exceedingly easy. Couple with an appropriate autotools project (autoconf, automake, etc.) and you really need do nothing more than write the library itself.

    If trying to create portable (Linux <-> Windows) libraries, you'll need to look up a few tricks like the __declspec extension to properly export/import symbols for .dlls. You'll also need to look up dlltool unless using an autotools project w/ msys or cygwin, which will take care of that for you.

  10. #10
    Join Date
    Apr 2012
    Beans
    1

    Re: HOWTO: Create C/C++ libraries in Linux (static and dynamic linking)

    Thanks for the link...

    great help...

Bookmarks

Posting Permissions

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