library linker input

Started by
2 comments, last by CJM 18 years, 7 months ago
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?
XBox 360 gamertag: templewulf feel free to add me!
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.
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
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

This topic is closed to new replies.

Advertisement