Linker errors when using boost :: filesystem?

I have the following code:

#include <iostream> #include <boost\filesystem.hpp> int main(){ const char* file_path = "my_path"; std::cout << boost::filesystem::file_size(file_path) << std::endl; } 

and when building I get the following errors:

 1>Main.obj : error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" ( ?system_category@system @ boost@ @ YAAEBVerror_category@12 @XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'native_ecat''(void)" ( ??__Enative_ecat@system @ boost@ @YAXXZ) 1>Main.obj : error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" ( ?generic_category@system @ boost@ @ YAAEBVerror_category@12 @XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'errno_ecat''(void)" ( ??__Eerrno_ecat@system @ boost@ @YAXXZ) 1>Main.obj : error LNK2019: unresolved external symbol "void __cdecl boost::filesystem::path_traits::convert(char const *,char const *,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > &,class std::codecvt<wchar_t,char,int> const &)" ( ?convert@path _traits@filesystem @ boost@ @ YAXPEBD0AEAV?$basic_string@ _WU?$char_traits@ _W@std @@ V?$allocator@ _W@2 @@ std@ @ AEBV?$codecvt@ _WDH@5 @@Z) referenced in function "void __cdecl boost::filesystem::path_traits::dispatch<class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > &,class std::codecvt<wchar_t,char,int> const &)" ( ??$dispatch@V ?$basic_string@ _WU?$char_traits@ _W@std @@ V?$allocator@ _W@2 @@ std@ @@ path_traits@filesystem @ boost@ @ YAXAEBV?$basic_string@DU ?$char_traits@D @ std@ @ V?$allocator@D @ 2@ @ std@ @ AEAV?$basic_string@ _WU?$char_traits@ _W@std @@ V?$allocator@ _W@2 @@ 4@AEBV ?$codecvt@ _WDH@4 @@Z) 1>Main.obj : error LNK2019: unresolved external symbol "public: static class std::codecvt<wchar_t,char,int> const & __cdecl boost::filesystem::path::codecvt(void)" ( ?codecvt@path @ filesystem@boost @@ SAAEBV?$codecvt@ _WDH@std @@XZ) referenced in function "public: __cdecl boost::filesystem::path::path<char const [1]>(char const (&)[1],void *)" ( ??$?0$$BY00$$CBD@path @ filesystem@boost @@ QEAA@AEAY00 $$CBDPEAX@Z ) 1>Main.obj : error LNK2019: unresolved external symbol "unsigned __int64 __cdecl boost::filesystem::detail::file_size(class boost::filesystem::path const &,class boost::system::error_code *)" ( ?file_size@detail @ filesystem@boost @@ YA_KAEBVpath@23 @ PEAVerror_code@system @ 3@ @Z) referenced in function "unsigned __int64 __cdecl boost::filesystem::file_size(class boost::filesystem::path const &)" ( ?file_size@filesystem @ boost@ @ YA_KAEBVpath@12 @@Z) 

I use Visual Studio and I set an additional library path for my linker to enable "C:\Program Files\Boost\boost_1_54_0\stage\lib;" . I also set the inclusion path to see C:\Program Files\Boost\boost_1_54_0;

Can anybody help? My code builds fine when I use boost :: algorithm, boost :: string and boost :: interprocess .

EDIT: this is what my link, if it is executed on the command line, looks like this:

/ OUT: "my_file_path" / MANIFEST / NXCOMPAT / PDB: "my_file_path" / DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32 .lib "" ole32.lib "" oleaut32.lib "" uuid.lib "" odbc32.lib "" odbccp32.lib "/ DEBUG / MACHINE: X64 / INCREMENTAL / PGD:" my_file_path "/ MANIFESTUAC:" level = 'asInvoker 'uiAccess =' ​​false '"/ ManifestFile:" my_file_path "/ ERRORREPORT: PROMPT / NOLOGO / LIBPATH:" C: \ Program Files \ Boost \ boost_1_54_0 \ stage \ lib "/ TLBID: 1

+7
c ++ boost visual-studio linker boost-filesystem
source share
6 answers

I had similar unauthorized creation of external objects in Visual Studio.
The solution was to use wchar_t for processing as inline.

+6
source share

You have the same problem as in How to resolve error LNK1104 using the Boost Filesystem library in MSCV? , and the answer is the same: Boost.Filesystem is dependent on Boost.System, and you need to link additionally with the latest library.

+2
source share

Set the linker flag /VERBOSE ("Linker | General | Show Progress" = "Show all progress messages (/ VERBOSE)" in the IDE). Then look at the exit; in the IDE, it will be located in the assembly output directory in a file named <project-name>.log .

If the accelerated file system library is being browsed, make sure it exists; if no one is looking for you, you will need to add the appropriate text explicitly in the linker attachments, as Dietmar KΓΌhl said in a recently deleted entry.

Also, since it looks like you are creating a target for x64, make sure that you are not trying to link to the 32-bit boost libraries.

+1
source share

There are many reasons why this error can occur. The reason is often hidden in warnings that follow or precede an error. The actual error message often tells you a little. For example, in my script, something like below is shown:

enter image description here

I use the VSColorOutput plugin, which colors errors and warnings differently. As you can see, the tooltip is displayed in a warning message that says:

 warning LNK4272: library machine type 'X86' conflicts with target machine type 'x64' 

This basically means that I compiled Boost libraries for the x32 target, but the project is x64 oriented. Thus, the fix was to delete the scene folder and execute the following command:

 b2 variant=debug,release link=static runtime-link=shared threading=multi --with-thread address-model=64 

If you do not see warnings, as indicated above, you can try to enable VERBOSE mode for Linker in the project settings> Linker> General> Show Progress.

Some other reasons for this error message to appear:

  • You did not compile the Boost installation at all or did not set the path in the project settings> Linker> General> Additional library directories. In this case, you may receive a message:

    fatal error LNK1104: cannot open file 'libboost_system-vc90-mt-gd-1_62.lib'

  • Another reason this could happen is because Boost may have been configured on your computer or in a project so as not to use names created by automatically generated libraries. This is called the automatic linking that Boost does by default, and this means that you do not need to explicitly specify .lib files explicitly in the project settings. Instead, Boost auto generates the lib file name and adds it to the linker. If it is disabled, you will receive an error message. It can be enabled using the macro BOOST_ALL_DYN_LINK at the project level.

+1
source share

This worked for me: I put #include boost / filesytem.hpp at the top of my code before referring to other headers.

 Link errors: #include <iostream> #include <fstream> #include <stdio.h> #include <Windows.h> //quantlib #include <ql/quantlib.hpp> //boost #include <boost/timer.hpp> #include <boost/lexical_cast.hpp> #include <boost/filesystem.hpp> --------------------------------------------- No Link errors: #include <iostream> #include <boost/filesystem.hpp> #include <fstream> #include <stdio.h> #include <Windows.h> //quantlib #include <ql/quantlib.hpp> //boost #include <boost/timer.hpp> #include <boost/lexical_cast.hpp> 
0
source share

The linker error was resolved by adding the following before including the header:

 define BOOST_SYSTEM_NO_DEPRECATED 
0
source share

All Articles