Why need .dll if I use static lib?

I

info

Hi!
Please be patient with a newbie...

I use DevC++.
I've found and compiled succefully various openGL examples.
Before build the application, I link the project with static libs,
like, in example, libglut32.a.

The executables running fine, but if I try them on a system without
glut32.dll, they don't start.

I'm a bit confused about libraries: if I use static libs, all code
should be included in final executable, right? ...so if I use
libglut32.a, why is needed glut32.dll?

I assume I'm compiling using static libs, because if I don't add the
libglut.a to project, the compiler return a link error. Besides I don't
see, in DevC++, an option like "compile using dynamic libs" and
goggling, I've found an article that explain that, to use dynamic libs,
it's needed a special code, like:

HMODULE LoadLibrary(LPCSTR lpFileName);
FARPROC GetProcAddress(HMODULE hModule, LPCSTR lpProcName);
BOOL FreeLibrary(HMODULE hModule);
etc...

And lines like these are not in files I'm compiling...

I've found a definition of static libs:
---------------
Just a collection of pre-compiled material declared in the relevant
header files. Needed by the linker. Include into the project.
---------------

So I can compile separately various cpp files, that contains all
functions definitions, to obtain various .o
Finally I compile all into a static lib, that is like "zipping" all .o
in a sort of special compressed file.

So, the .a has ALL I NEED! All objects are into the .a, so the .dll is
not needed...

I've just try to compile a simple static lib and use it in a basic
project...it work, without dll!

An example here:
http://www.crasseux.com/books/ctutorial/Building-a-library.html

but using DevC++ is more simple, just choose "static lib" in project
option and compile it.
Later, make a new project that use some functions defined in lib, and
compile it after added the lib to project...

So, I don't understand what happen when I link the linglut32.a or
opengl.a, and why the application need anyway glut32.dll and
opengl32.dll...

Thanks,

Manuel
 
W

W Marsh

Hi!
Please be patient with a newbie...

I use DevC++.
I've found and compiled succefully various openGL examples.
Before build the application, I link the project with static libs,
like, in example, libglut32.a.

The executables running fine, but if I try them on a system without
glut32.dll, they don't start.

I'm a bit confused about libraries: if I use static libs, all code
should be included in final executable, right? ...so if I use
libglut32.a, why is needed glut32.dll?

This is off-topic - it's not a C++ language question. Ask somewhere
more appropriate, and search Google for "import library".
 
J

Jim Langston

Hi!
Please be patient with a newbie...

I use DevC++.
I've found and compiled succefully various openGL examples.
Before build the application, I link the project with static libs,
like, in example, libglut32.a.

The executables running fine, but if I try them on a system without
glut32.dll, they don't start.

I'm a bit confused about libraries: if I use static libs, all code
should be included in final executable, right? ...so if I use
libglut32.a, why is needed glut32.dll?

I assume I'm compiling using static libs, because if I don't add the
libglut.a to project, the compiler return a link error. Besides I don't
see, in DevC++, an option like "compile using dynamic libs" and
goggling, I've found an article that explain that, to use dynamic libs,
it's needed a special code, like:

HMODULE LoadLibrary(LPCSTR lpFileName);
FARPROC GetProcAddress(HMODULE hModule, LPCSTR lpProcName);
BOOL FreeLibrary(HMODULE hModule);
etc...

And lines like these are not in files I'm compiling...

I've found a definition of static libs:
---------------
Just a collection of pre-compiled material declared in the relevant
header files. Needed by the linker. Include into the project.
---------------

So I can compile separately various cpp files, that contains all
functions definitions, to obtain various .o
Finally I compile all into a static lib, that is like "zipping" all .o
in a sort of special compressed file.

So, the .a has ALL I NEED! All objects are into the .a, so the .dll is
not needed...

I've just try to compile a simple static lib and use it in a basic
project...it work, without dll!

An example here:
http://www.crasseux.com/books/ctutorial/Building-a-library.html

but using DevC++ is more simple, just choose "static lib" in project
option and compile it.
Later, make a new project that use some functions defined in lib, and
compile it after added the lib to project...

So, I don't understand what happen when I link the linglut32.a or
opengl.a, and why the application need anyway glut32.dll and
opengl32.dll...

I believe the answer is that the static lib you are linking to is calling
the dynamic library itself.

Althought this is really a windows questions, you should try in
microsoft.public.vc.language as I could be totally wrong.
 
P

Paul Henderson

So, I don't understand what happen when I link the linglut32.a or
opengl.a, and why the application need anyway glut32.dll and
opengl32.dll...

Quick reply only as you're off-topic: under Windows, you need to link
with a .lib / .a when you're calling a DLL - basically, the lib
resolves the linker symbols for the DLL functions - telling it to load
them from the DLL at startup; hence you still need the DLL. LoadLibrary
etc. is usually needed if you only know which DLLs are needed at
runtime [not the case here].
 
M

Manuel

Paul said:
Quick reply only as you're off-topic: under Windows, you need to link
with a .lib / .a when you're calling a DLL - basically, the lib
resolves the linker symbols for the DLL functions - telling it to load
them from the DLL at startup; hence you still need the DLL. LoadLibrary
etc. is usually needed if you only know which DLLs are needed at
runtime [not the case here].

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top