1

In C++, what are .lib and .dll files, how can they be created, and are they a way of enabling the user to access functionality implemented in .cpp files without actually having those files?

In particular, I have writen code containing a few classes that I want to give to someone else to use, but I don't want to give them the .cpp file containing my implementation.

PS: I am using CodeBlocks.

Ben
  • 15,938
  • 19
  • 92
  • 138
  • For instruction on how to create them: http://stackoverflow.com/questions/584041/how-do-i-build-an-import-library-lib-and-a-dll-in-visual-c – marcinj Dec 30 '11 at 17:29

1 Answers1

6

Lib and dll files are libraries that are created in the usual way, with special switches to the compiler to tell what kind of output file you want.

A lib file is a static library that is linked with your main cpp program once, at link time, to yield a self-contained exe file that needs nothing else to run. A dll (Dynamic Link Library) is linked with your main cpp application each time that application is loaded, thus "dynamic." No, there is no way a user can get at your cpp source code from either of these two kinds of libaries. A lib file is analogous to a Linux/Unix .a file; a dll is analogous to a Linux/Unix .so file.

Your source code is completely safe, with one exception:

Any global variable names or function names that are available to your main cpp application are present in the lib file and in the dll in text form. If one examines a lib file or a dll he can see these global names and function names in plain text form: only the names themselves -- just the names and nothing more.

Your sources are quite safe. You'd give out your exe file plus the dll if it were linked dynamically; or just the exe if it were linked statically, which would be my preference if I were you.

I think I'm correct in saying that. If I'm not, I am sure that someone here on SO will be happy to tell me all about it :-)

HTH

Pete Wilson
  • 8,610
  • 6
  • 39
  • 51
  • 1
    @Ben, you would compile a lib file and if someone wanted to write something using your library they would have to link against it. You also provide some header files to let developers know what parameters a function takes/returns, for example. – David Titarenco Dec 31 '11 at 00:34
  • David's answer was in response to: What I want to do is give someone the ability to use my classes, but without my .cpp files. I don't want to give them any executable, just the classes so that they can use them to build their own executable. Say, someone wants to built a car and I go, hey, use my carradio that has methods for playing and pausing music! Having an exe for the carradio on its own would be pretty pointless cause it only makes sense in someones car. So how would I do that? – Ben Dec 31 '11 at 00:37
  • @David Thank you, that helps my understanding! Now could someone explain, how I can compile a lib file for a CodeBlocks project? – Ben Dec 31 '11 at 00:40