How do I link a static lib when writing my own library?

Started by
4 comments, last by dviator 22 years, 1 month ago
Hi.. I''m trying to write a static library that makes use of OpenGL, and I''m unsure of whether I need to link to opengl32.lib or not. I''ve included gl.h in one of the headers. I''m using MSVC++ 6, and in Project/Settings there isn''t a Link tab. So I guess the question is do I, or can I, link a static .lib like opengl32.lib for instance when creating my own static library? This way when I''m using my library I can just add mylib.lib to a project without having to add opengl32.lib as well. I already know about using a pragma comment, is that the only way to do this? Thanks
Advertisement
quote:Original post by dviator
So I guess the question is do I, or can I, link a static .lib like opengl32.lib for instance when creating my own static library?

You can. Whether you should is up to you.

quote:I already know about using a pragma comment, is that the only way to do this?

You can add the names of libraries to link in Project Settings MSVC).

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
quote:You can add the names of libraries to link in Project Settings MSVC).


If you create a new Win32 Static Library project in MSVC, there is no Link tab under Project/Settings. Any ideas?
quote:Original post by dviator
If you create a new Win32 Static Library project in MSVC, there is no Link tab under Project/Settings. Any ideas?

In that case, #pragma is your only option.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
#pragma is not necessary (tho, it will work). under your project settings, there is a "library" tab. you can add linker settings there. the preferred method tho, would be to add the ".lib" file to your project files under the project workspace.

right-click on the project and select "add files to project" from the pop-up menu. select "Library Files (.lib)" for the "Files of type" and then locate and add your library file. done deal.

NOTE: "OpenGL32.lib" is NOT a static library file in the sense that your talking about. it''s actually a link to the "OpenGL32.dll" file, but does not contain object information (i.e. data and instructions). a static library (better named "archive") does.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Doh. Forgot about just simply adding the file to the project. Thanks for the help guys.

This topic is closed to new replies.

Advertisement