Thread: DLLs?

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    6

    DLLs?

    Hi All

    Firstly apologies if this is a silly question, but I am quite new to C programming.

    All the C I've done has been on Ubuntu, and I'm now attempting to compile a C program on Windows (in console mode) which will connect to a MySQL database. The program works ok but it needs libmysql.dll, so if I were to run the program on another machine I'd need to take that file also.

    Considering my program is about 10k it seems ridiculous to carry over a 2 meg library file just so it will run. This is by no means a criticism of Windows as of course Linux has it's libraries too. But my question is:

    Is there a way to embed or include the DLL (or it's useful components) into my program at compilation time so I only have one file to distribute?

    Thanks for any advice

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Just my 2c, but wouldn't you need to install a mysql client connection for that database.
    As DLLs are akin to shared libs on *nix I'd assume that some software needs to be installed.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by jhp View Post
    Considering my program is about 10k it seems ridiculous to carry over a 2 meg library file just so it will run.
    That's like saying "I just want to add 2 numbers ... and have it displayed in an actual window in Windows, complete with minimize/maximize buttons and the whole nine yards, but all I am doing is adding two numbers, so why do I have to have a bunch of stuff linked to it?"


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by jhp View Post
    Is there a way to embed or include the DLL (or it's useful components) into my program at compilation time so I only have one file to distribute?
    The whole point of any dynamically loaded/shared library is that it is not part of the executable, so the executable stays relatively small, and many programs can share one copy of the library. Putting the DLL into your program would make it a statically linked library and, as Quzah pointed out, make the size bigger.

    The "single distribution file" can be achieved by packaging your program with the DLL and a small install script. The install script should check if there is an appropriate version of the DLL already installed on the system, and if not, install the one you provide. I'm a Linux guy, so I don't know how to do all that in Windows, but that would be a preferred solution, IMO.

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by anduril462 View Post
    The "single distribution file" can be achieved by packaging your program with the DLL and a small install script. The install script should check if there is an appropriate version of the DLL already installed on the system, and if not, install the one you provide. I'm a Linux guy, so I don't know how to do all that in Windows, but that would be a preferred solution, IMO.
    Then the user uninstalls some other application, the installer for that app is broken and it removes the DLL you were relying on and you're dead. Really blows.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by brewbuck View Post
    Then the user uninstalls some other application, the installer for that app is broken and it removes the DLL you were relying on and you're dead. Really blows.
    Good point. What would a practical solution to this be. Just leave a local copy of the DLL in your directory? Kinda defeats the purpose, especially for something common like libmysql. Is there some way to register dependency with Windows so that some other installer couldn't accidentally delete it?

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    6
    Quote Originally Posted by quzah View Post
    That's like saying "I just want to add 2 numbers ... and have it displayed in an actual window in Windows, complete with minimize/maximize buttons and the whole nine yards, but all I am doing is adding two numbers, so why do I have to have a bunch of stuff linked to it?"
    Hah! Well I guess it is like that. But my point is that if I have a bunch of include files to make my program work, then in theory shouldn't my stand alone program contain relevant portions of code sufficient to make it work as a standalone? There's no client package installed to make it do stuff, just mysql headers and the dll.

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    #include doesn't get you any code -- it just gets you function prototypes, defines, et cetera. The code lives in the library, which is why you link to it (static or dynamic at your leisure).

  9. #9
    Registered User
    Join Date
    Jun 2011
    Posts
    30

    Smile

    Thought of a a self-extractor??
    For a single executable??

  10. #10
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    I'd just use a setup program like Inno Setup and keep a copy of the required DLLs in our program's home folder. It's very unlikely any other uninstaller would go there to remove them and they load much faster that way.

  11. #11
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    431
    Quote Originally Posted by jhp View Post
    Hi All
    Is there a way to embed or include the DLL (or it's useful components) into my program at compilation time so I only have one file to distribute?
    It's called static linking. In my opinion, this is the preferable route if you're not going to do a proper installer. If you put the dll in the executable directory, you can run into problems running side by side with another program that does the same thing.

    I think the static version of libmysql is called mysqlclient.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  12. #12
    Registered User
    Join Date
    Jun 2011
    Posts
    6
    Ah I understand now, I was confused about the includes. I think the best case, then, is to put the dll in the program folder (if it's legally distributable anyway).

    Thank you all for your comments, appreciated.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DLLs in c++
    By MisterT in forum C++ Programming
    Replies: 4
    Last Post: 08-05-2006, 04:18 PM
  2. VB DLLs with C++
    By confuted in forum Tech Board
    Replies: 1
    Last Post: 10-31-2003, 09:36 AM
  3. mfc DLLs
    By fizisyen in forum C++ Programming
    Replies: 5
    Last Post: 02-21-2003, 08:59 PM
  4. DLLs? anyone?
    By Liger86 in forum C++ Programming
    Replies: 7
    Last Post: 12-26-2002, 06:55 PM
  5. Using C DLLs in VB
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 10-10-2001, 02:58 PM

Tags for this Thread