Linking versus Dynamic Loading / MySQL

This is a discussion on Linking versus Dynamic Loading / MySQL within the C Programming forums, part of the General Programming Boards category; I'm writing a small MySQL program in C (Well, I'm writing it in C++ at the same time as well). ...

  1. #1
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309

    Linking versus Dynamic Loading / MySQL

    I'm writing a small MySQL program in C (Well, I'm writing it in C++ at the same time as well).

    In both apps, I am linking the libmysql libraries.

    If I wanted to load them and call them at runtime instead, how is that done?

    Thanks.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  2. #2
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    I assume you are referring to loading the library at runtime?

    Depends on the platform. For windows, you'll need to use LoadLibrary and then GetProcAddress to retrieve the addresses of the functions, as far as I know. I'm not sure if there's an easier way to do it.

    On Linux, you use shared objects and the accompanying functions to load it(dlopen and others mentioned in the man page for dlopen).
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  3. #3
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    I'm on a Mac.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Typing man ld on my Mac got me this:
    A dynamic library (aka dylib or framework) is a final linked image.
    Putting a dynamic library on the command line causes two things: 1) The
    generated final linked image will have encoded that it depends on that
    dynamic library. 2) Exported symbols from the dynamic library are used to
    resolve references.
    I haven't tried it out, though.

  5. #5
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    Quote Originally Posted by Dino View Post
    I'm on a Mac.
    I have used a mac for a total of 10 minutes in all my life, or so. I do however know it's based on Unix, so you might be able to use dlopen.
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  6. #6
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Yes, looks like dlopen() (et al) are the functions to call. Found this on apple's web site: Mac Dev Center: Dynamic Library Programming Topics: Introduction

    I'm coding up a test program and dynamic lib this afternoon to see how they work. Thanks. I'll post here when I'm done.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Linking & Memory usage
    By @nthony in forum C Programming
    Replies: 2
    Last Post: 06-02-2007, 09:57 PM
  2. Dynamic loading with C++
    By karas in forum Linux Programming
    Replies: 7
    Last Post: 12-25-2006, 01:13 AM
  3. Explicit dynamic linking
    By mkyong in forum Windows Programming
    Replies: 9
    Last Post: 01-14-2003, 04:46 AM
  4. Win32 API - Dynamic Link Library Loading - behind the scenes
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 04-05-2002, 07:31 AM
  5. Dynamic Linking in DOS... important!
    By minime6696 in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 01-26-2002, 10:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21