# Linking Boost as a static library

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

## Recommended Posts

Hi Team! I'm using Boost::threads, I've created a staticly linked lib project in VC7.1, and now i am looking to link it into my main application, but the application fails to link completely because of some form of annoying automatic linking mechanism. I get this error: fatal error LNK1104: cannot open file 'libboost_thread-vc71-mt-sgd-1_33_1.lib' Any ideas how i can link this using my library (I don't like they way boost does it's linking, I need to use my own MSVC project for the linking) Thanks All! --Josh P.S. I realise boost.org should have the information i need, but it is currently down at the moment, and I'm trying to get this done asap. Any hints would be appreciated, even if you arn't 100% sure about the details! thanks! [Edited by - JoshG on October 18, 2006 7:52:58 AM]

##### Share on other sites
Is "libboost_thread-vc71-mt-sgd-1_33_1.lib" the file you want to link against, or the file that Boost is automatically trying to link against that you want to prevent?

If the former, it just sounds like your library search paths are not set up to point to where all the Boost libraries are.

If the latter, the Boost libraries usually respect a preprocessor definition to suppress the linking. For Boost.Regex it is BOOST_REGEX_NO_LIB, I would imagine its similar for Boost.Threads.

(I keep getting 403 Forbidden results from Boost's website when I try to search their site, so I can't look it up right now).

##### Share on other sites
I build boost like that:

bjam -sTOOLS="vc_8-0" -install

the -install switch copies all the libs to a single directory.

then u can just add /LIBPATH:"<directory goes here>" to the linker command line options of ur project. boost headers will set up linking agains the correct lib using #pragmatas.

so everything should go smooth. :-)

Cheers Jochen

##### Share on other sites
I build boost like that:

bjam -sTOOLS="vc_8-0" -install

the -install switch copies all the libs to a single directory.

then u can just add /LIBPATH:"<directory goes here>" to the linker command line options of ur project. boost headers will set up linking agains the correct lib using #pragmatas.

so everything should go smooth. :-)

Cheers Jochen

##### Share on other sites
Yeah, I'm trying to do the "Latter"

I DON'T want to use boost's automatic linking

I've created the following file:

#define BOOST_THREAD_NO_LIB#include "boost/thread.hpp"typedef boost::thread BoostThread;typedef boost::thread_group ThreadGroup;typedef boost::recursive_mutex RecursiveMutex;typedef RecursiveMutex::scoped_lock ScopedLock;typedef boost::condition Condition;

and that is what I'm using to include any reference to boost::threads... But as showed before it still gives out that linking error to the file i don't want it to link to... I can't even find the mechanism its using to do the automatic linking to disable it!

I've also tried:

just incase that might work, but no luck either

----------------------------------
In response to the other replies above, Sorry i didn't make it clear before, I wish to SUPPRESS the automatic linking of the boost library, so i can provide the functions in my own way.

And thanks for the link BuBu, that made me realise that the site that google is reporting "www.boost.org" is the site that is down, "boost.org" seems to be fine

##### Share on other sites
You might try searching the Boost source tree for the string "libboost_thread-vc71-mt-sgd-1_33_1.lib" since the library is likely to be linked against via a #pragma comment directive. You might be able to examine the surrounding code and look for the gating condition to suppress the link.

What exactly do you mean by "provide the functions in your own way," though? Do you just want to manually link the library?

##### Share on other sites
Yeah, did some backtraceing, found the issue,

I had to #define BOOST_THREAD_BUILD_LIB inside my own version of the library
as it did not automatically realise that it was building a library

Thanks for the replies all, appreciate your interest petrie!

--Josh