It is obvious you are asking a Windows specific question. There is nothing wrong with that in this sub forum within LQ. But it might have helped to explicitly state that you want Windows specific help (to avoid confusing anyone who might otherwise try to give a Linux answer).
Quote:
Originally Posted by PinoyAko
I already compiled zlib1.dll and zlib.lib
|
You may need to be more precise in that statement, and why zlib
1 vs. zlib? Or was that just a typo in your post?
As part of creating zlib1.dll you normally create an interface .lib file (is that zlib.lib?). Then you can use the interface .lib file at link time to indicate use of the .dll at load time.
But, you might alternately or also have created a .lib file independently from the same source code as the .dll (is that what zlib.lib is?) such that the .lib used at link time is statically linking those functions instead of specifying use of the .dll at load time.
Quote:
My understanding is if you are using zlib.lib you are statically linking therefore the functions/codes in zlib will be compiled within my project.
|
In Windows, you use a .lib either way (for static or dynamic link of the specified functions). The difference occurs when you build that .lib file (do you build it as an interface .lib while building the .dll or do you build it as a static .lib independently from the same source code as the .dll).
In Linux (and other POSIX and POSIX-like systems), you include a .lib file at link time to statically link the contents, or you include a .so file at link time to dynamically link the contents. If you have used or read about that sensible system, then the Microsoft kludge of using two different kinds of .lib may be confusing you.
Quote:
Is there any other way to not use "pragma comment(lib, "zlib1.lib")"
|
You could specify the .lib name as part of the link command, rather than in the source code. In Visual Studio there is some GUI step where you specify .lib files to be included in the link command the GUI auto generates for you (but I forget exactly where that is in the GUI). You can also directly override the link command to add anything you want, but that is normally not done for including an ordinary .lib.
But why don't you like that pragma? That seems a more robust way to manage the need for a library vs. specifying the function declarations (the .h file) far away from specifying the linkage to the lib.