Marco
Marco

Reputation: 1

Why do I get a linker error using the Boost Filesystem in C++?

I have the following code:

#include <boost\filesystem.hpp>

int main()
{

    return 0;
} 

But when I try to compile it, I get the following linker error:

fatal error LNK1104: cannot open file 'libboost_filesystem-vc100-mt-gd-1_46.lib':

How can I fix it?

Upvotes: 0

Views: 1740

Answers (3)

Marco
Marco

Reputation: 1

I just followed the following instructions from the site of boost:

From Visual Studio's File menu, select New > Project…

In the left-hand pane of the resulting New Project dialog, select Visual C++ > Win32.

In the right-hand pane, select Win32 Console Application (VS8.0) or Win32 Console Project (VS7.1).

In the name field, enter “example”

Right-click example in the Solution Explorer pane and select Properties from the resulting pop-up menu

In Configuration Properties > C/C++ > General > Additional Include Directories, enter the path to the Boost root directory, for example

C:\Program Files\boost\boost_1_46_0

In Configuration Properties > C/C++ > Precompiled Headers, change Use Precompiled Header (/Yu) to Not Using Precompiled Headers.3

Replace the contents of the example.cpp generated by the IDE with the example code above.

From the Build menu, select Build Solution.

Upvotes: 0

CygnusX1
CygnusX1

Reputation: 21769

Google translate: "Unable to open file"

I suspect that you didn't provide the lib path to boost libs in:

Project properties -> Linker -> General -> Additional Library Directories

Upvotes: 1

Ralf
Ralf

Reputation: 9573

Boost uses auto-linking so by including the file system header, it automatically tries to locate the corresponding lib files.

Make sure that the boost lib directory (wherever the lib files are located) is in your visual studio/project library path.

Upvotes: 2

Related Questions