Jump to content
  • Advertisement
Sign in to follow this  
templewulf

library linker input

This topic is 4824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering if any of you excellent folks could tell me if there were a way to link a static library (.lib) to a project in text form. For instance, header files are fairly obvious because they're declared IN the code with a #include. Linker inputs aren't so obvious, because you have to go into project settings. I've been using #pragma comment(lib, "something.lib"), but I've heard it's a bit flaky on non-MS compilers. Is there a more standards-compliant substitute?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Is there a more standards-compliant substitute?


I have yet to come across anything of this nature. Best bet is to bite the bullet and add in the linker lines. I usually just place the linker line needed for a particualr source file in a comment at the top so I can easily do a copy/paste when I add it to a new project.

Share this post


Link to post
Share on other sites
What you're looking for is a build system, and there are plenty of them out there. They go from fairly simple to quite elaborate. You might want to consider make, nmake, cmake and my personal preference - SCons.

The beauty of SCons is that you need to specify the name of the library that you want and scons takes care of the messy details like what prefixes and suffixes you should have ( lib<name>.so, lib<name>.a on most linux varieties or <name>.lib and <name>.dll under windows ).

It's even fairly simple to call SCons from visual studio using a tweaked makefile project

Share this post


Link to post
Share on other sites
Hey,

My personal preference is the #pragma comment(), but I'd say that this is one of those areas that #defines are still useful. My El Dodgo way would be to write a block which checks to see if the compiler is one which supports #pragma comment(), otherwise to throw an error of some variety.

That way, when someone moves your code to a new compiler, they try to compile, and if it doesn't support #pragma comment, then they get a message saying "LibName.lib could not be automatically included. Include it and then comment out this line."

That way, users who aren't using MSVC or other comatible compilers will be informed about why they're getting a whole load of unresolved symbols. The only time that they're going to have to worry about adding libs themselves are when they add new code, code in which the errors aren't commented out.

Or you could put multiple defines into a header as a long macro, and incorporate multiple compilers through the one line that way.

Of course, all of this would be easily improved by a standard "load static library" command somewhere, and if someone has a platform independent method, then that'd be nice.

-- CJM

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!