|
-
August 29th, 2003, 07:22 PM
#31
Originally posted by bytz
Re-read the following sentence:
If you specify a normal lib, it gets linked statically. If you specify a dll, it gets linked dynamically.
Further explaination:
It depends on the type of library you create!!!!! If you create a normal lib; from then you will link it statically, no choice, no decision, it just the way it works. If on the other hand you created a DLL, when you used it in a application it would linked using dynamic linking, once again no choice, no decision. Once a library has been created there is no choice how to link it -- well, almost none; you can choose not to link a dll, but to load it programmatically at runtime.
The only choice you could have with one of you libraries is too create both a static version and a dynamic version. Then you could choose one or the other and the linking would occur as determined by the lib type .
Excellent! Now it is going back to my initial question if you still remember, which is why I have to link a .lib file when I use DLL.
My concern #1:
Why after I specify DLL, both DLL and LIB files are generated?
I think if I specify DLL, then ONLY DLL will be generated eventually and if I specify LIB, then only LIB will be generated.
My concern #2:
Why I have to link the .lib files when I specify DLL.
In order to confirm what I thought, I wrote a dummy application in the following(please note, they all are verified)
// Client.cpp
#include "testLib.cpp"
int main(int argc, char* argv[])
{
Speak("Hello, library\n");
return 0;
}
// testLib.cpp
#include <iostream>
#include <windows.h>
using namespace std;
int Speak(LPTSTR szText)
{
cout<<szText<<endl;
return 1;
}
//testDLL.cpp
#include <iostream>
#include <windows.h>
using namespace std;
int Speak(LPTSTR szText)
{
cout<<szText<<endl;
return 1;
}
testDLL is a dynamic link library and testLib is a static link library.
Under folder testDLL, ONLY testDLL.dll were generated!
Under folder testLib, ONLY testLib.lib were generated!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|