Thread: Linking versus Dynamic Loading / MySQL

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

    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.
    Mainframe assembler programmer by trade. C coder when I can.

  2. #2
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    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
    Chappell Hill, Texas
    Posts
    2,332
    I'm on a Mac.
    Mainframe assembler programmer by trade. C coder when I can.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    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
    477
    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
    Chappell Hill, Texas
    Posts
    2,332
    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.
    Mainframe assembler programmer by trade. C coder when I can.

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, 02:13 AM
  3. Explicit dynamic linking
    By mkyong in forum Windows Programming
    Replies: 9
    Last Post: 01-14-2003, 05: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, 08: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, 11:50 PM