Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link Boost in a dependent static library

Tags:

In MS Visual C++ 2010

I had a single C++ project in my solution which used boost and worked perfectly.

I then decided to convert this project into a static library and create a new project which depends on this static library.

Now, my converted static library builds without errors and warnings (compiler and linker) but the new project compiles but does not link.

I am getting:

1>LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc100-mt-1_45.lib' 

As a test I added the full directory path to the linker options for this library... and then it complained about

1>LINK : fatal error LNK1104: cannot open file 'libboost_date_time-vc100-mt-1_45.lib' 

I have now added complete paths to all the libraries and it now builds and run.

I am not happy with this solution because:

  1. I don't want users of the library to have to worry about linking in boost.
  2. It is messy

I know an answer would be to create a DLL but is there a way to do this statically and keep the linking at my static library level.

Edit:

If I tell the .exe linker to ignore the boost libs explicitly then it all is ok except the .exe should not have to worry about boost at all.

/NODEFAULTLIB:"libboost_thread-vc100-mt-1_45.lib" /NODEFAULTLIB:"libboost_date_time-vc100-mt-1_45.lib" 
like image 665
T33C Avatar asked Jan 19 '11 15:01

T33C


People also ask

How do I link my Boost library to Visual Studio?

6.1 Link From Within the Visual Studio IDE Right-click example in the Solution Explorer pane and select Properties from the resulting pop-up menu. In Configuration Properties > Linker > Additional Library Directories, enter the path to the Boost binaries, e.g. C:\Program Files\boost\boost_1_55_0\lib\.

How do I link a static library?

Static libraries are created by copying all necessary library modules used in a program into the final executable image. The linker links static libraries as a last step in the compilation process. An executable is created by resolving external references, combining the library routines with program code.

How do I contribute to Boost library?

To participate in development, you need to subscribe to the Boost developers' list. Once you've done that, some paths to contribution are: Submit patches for new features or bug fixes. Pick any ticket from our bug tracking system on GitHub and get started.


1 Answers

Apparently you don't need the .libs, as your exe also links without them. You seem to be using boost header-only methods and classes. So just tell boost to disable auto linking by defining the preprocessor symbol BOOST_ALL_NO_LIB in your project.

If you want to make your .lib unnecessary big by including all of boost, this question seems to hold an answer (which I never really tried myself): Linking static libraries to other static libraries

like image 66
user52875 Avatar answered Nov 17 '22 01:11

user52875