Proper DLL use

Started by
12 comments, last by DvDmanDT 11 years, 10 months ago

[quote name='Nazzrim' timestamp='1338301601' post='4944323']
@Radikalizm
I think I got it now ;-). If I link dynamic there is no need of a Link-flag, because everything gets resolved at runtime. But if I don't want to link dynamic I have to tell the Linker where to look.

If I seperate the #include from the rest in my mind, there is no need of an include statement if I use dynamic link, because then I would be forced to include everything out of the header file.
But how can I get access on classes/flags used inside a DLL.
And not special for SDL: Why can there be more than one linker-flag for one DLL? Can a DLL contain different separated libraries?
Hopefully the last two are not SDL specific and more like "problems of general DLL usage" ;-).


You're still confusing your concepts; as I said, the include statement has absolutely nothing to with linking, so there's no association to be made between static/dynamic linking and including header files.
I think you should maybe pick up a book on programming in C++ to get your concepts straight, a forum isn't exactly the right place to learn all these elementary things smile.png
[/quote]

Maybe I didn't point out my thoughts clearly: If I use the include statement, the whole content of the header file is included into my executable and because there is no implementation of the functions the Linker will look at the locations I tell it.
I think I nearly understood the concept of include statement / dynamic/static link (will do some practice on that) but maybe I am not able to find the right words...

My actual problem is that I don't know how to handle this information in C++, or: How does a static/dynamic link look in C++?
Until know I thougt thats its static if I use Link-Flags and if not its dynamic.

And yes you are right, I thougt my problem is a lot smaller, but I think I should consider some lecture.
But thank you very much:-).

@DvDmanDT: Thank you. Hopefully got it.
Advertisement
When you compile something in C/C++, you compile one source file (ie .c, .cpp or .cxx) at a time. Now, obviously each source file cannot contain all functions/classes/whatever, so you use a .h/.hpp/.hxx file to say "this function/class/whatever is available, but it's content is defined elsewhere". It does not specify where, just that it exists. The compiler therefore inserts stuff like "Insert call to FUNC here" in the .obj file which contains the program code from it's respective .c/.cpp/.cxx file.

Then you invoke the linker to combine all .obj and .lib/.a files into an .exe (or a .dll/.so, or even another .lib/.a). There are two types of libraries (.lib/.a), import libraries and static libraries. The static libraries contains the actual definitions of it's functions/classes/whatever, while import libraries just says "the contents of my stuff reside in whatever.dll or whatever.so". Both static and import libraries are .lib or .a files, included with the same linker flags (ie -lSDL) and the only way to know if it's a static library or an import library is to look in the documentation of that library (or use tools to examine them or whatever).
DvDmanDT:
Okay, does that mean that the way a library is linked is determined only by the library and not by the way I actual code it? If it does I got it :>.
I didn't know that a library "sets itself" to static/dynamic. Maybe I should get information about DLL's in general.

With this, kept in mind the following sentence I found on SDL site makes sense to me, because now I know that this resulting the dll being a dynamic one.
And if I want to know if a library is dynamic or static I have to examine the library itself.
Helped me a lot. Thank you


Can I use SDL in a commercial application?

Yes! If you link dynamically (via .dll's, .so's or using other dynamic linking devices) then you do not need to to anything. If you link statically (include the SDL source inside your project when you compile) you have to provide some way for your customer to relink your application a custom version of SDL.
[/quote]
If I understand your question, then yes. It's determined by the library, not how you use it in your code or what flag you pass when you link against the library.

When you create a library, you select whether you want to create a static library or a dynamic library (I think that's the terminology used in VS). If you choose to create a dynamic library, then both a .dll and a .lib file will be created, if you choose to create a static library you'll only get a .lib.

A static library is often quite large (hundreds to thousands of kbs) while an import library (the .lib file which just includes references to its .dll) is isually in the 5-20 kb range.

This topic is closed to new replies.

Advertisement