Dmitriy Bobrov
Dmitriy Bobrov

Reputation: 9

Error with linking Boost::Filesystem with Conan and CMAKE? What to do?

Here's source code

#define BOOST_SYSTEM_DYN_LINK
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/asio.hpp>
#include <boost/regex.hpp>
#include <boost/system.hpp>
#include <string>

int main() {
boost::filesystem::path p("C://");
boost::regex xRegEx("(\\w+)-(\\d+)-(\\w+)-(\\d+)");
return 0;
}

Errors:

[build] 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,struct _Mbstatet> const &)" (?convert@path_traits@filesystem@boost@@YAXPEBD0AEAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@AEBV?$codecvt@_WDU_Mbstatet@@@5@@Z) referenced in function "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> > &)" (?convert@path_traits@filesystem@boost@@YAXPEBD0AEAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z) [C:\Users\bobrov\project\scanner\build\scanner.vcxproj]
[build] main.obj : error LNK2019: unresolved external symbol "public: static class std::codecvt<wchar_t,char,struct _Mbstatet> const & __cdecl boost::filesystem::path::codecvt(void)" (?codecvt@path@filesystem@boost@@SAAEBV?$codecvt@_WDU_Mbstatet@@@std@@XZ) referenced in function "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> > &)" (?convert@path_traits@filesystem@boost@@YAXPEBD0AEAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z) [C:\Users\bobrov\project\scanner\build\scanner.vcxproj]
[build] C:\Users\bobrov\project\scanner\build\bin\scanner.exe : fatal error LNK1120: 2 unresolved externals [C:\Users\bobrov\project\scanner\build\scanner.vcxproj]
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/bobrov/project/scanner/build --config Debug --target scanner -j 8 -- exited with code: 1
[driver] Build completed: 00:00:03.828
[build] Build finished with exit code 1

CMakeLists.txt

cmake_minimum_required(VERSION 3.2)
project(scanner CXX)

set(CMAKE_CXX_STANDARD 17)
set(CONAN_DISABLE_CHECK_COMPILER "1")
set(SOURCES src/main.cpp)

if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
        include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
        conan_basic_setup()
    else()
        message(WARNING "The file conanbuildinfo.cmake doesn't exist, you have to run conan install first")
    endif()

set(Boost_USE_STATIC_LIBS ON)

find_package(Boost COMPONENTS system filesystem regex REQUIRED)

if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS})
    add_executable(${PROJECT_NAME} ${SOURCES})
    target_link_libraries(${PROJECT_NAME} ${BOOST_LIBRARIES})
endif()

conanfile.txt

[requires]
boost/1.80.0

[options]
boost:header_only=False
boost:without_stacktrace=True

[generators]
cmake
virtualenv
cmake_find_package

conan task

        {
            "label": "conan install win_msvc_x86_64",
            "type": "shell",
            "command": "conan install -pr:b win_msvc_2019_x86_64 -pr:h win_msvc_2019_x86_64 -if \"${command:cmake.buildDirectory}\" \"${workspaceFolder}\" --build missing",
            "problemMatcher": []
        }

conan profile

[settings]
os=Windows
os_build=Windows      
arch=x86_64
arch_build=x86_64     
compiler=Visual Studio
compiler.version=17   
build_type=Release    
[options]
[conf]
[build_requires]      
[env]

Please, help!

I read next info that gave no profit: Linker errors when using boost::filesystem? Unresolved external symbol in Boost filesystem library (error LNK2019) and official docs

Upvotes: 0

Views: 172

Answers (0)

Related Questions