Théo Champion
Théo Champion

Reputation: 1988

MSVC 2017 missing libboost_filesystem-vc141-mt-gd-x32-1_66.lib error

I'm trying to create a dynamic library on Windows but I have a problem with Boost, I keep getting this error

1>LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc141-mt-gd-x32-1_66.lib'

The thing is, according to this http://www.boost.org/doc/libs/1_66_0/more/getting_started/windows.html#header-only-libraries the two librairies are supposed to be header only header only

the cmake i'm using

cmake_minimum_required(VERSION 3.8)

project(mod_autoindex)

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")

SET (BOOST_ROOT "C:/Program Files (x86)/boost/boost_1_66_0")
SET (BOOST_INCLUDEDIR "${BOOST_ROOT}/boost")

if (UNIX)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra")
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
else()
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()

include_directories(${Boost_INCLUDE_DIR})
include_directories("../../include")
include_directories("../../include/sza")
include_directories("./include")


file(GLOB_RECURSE CPP_SRCS ${CMAKE_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE HEADERS ${CMAKE_SOURCE_DIR}/include/*.hpp)

set(SOURCE_FILES ${CPP_SRCS} ${HEADERS})
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME})

Any idea of wrang am i doing wrong ?

cmake output for cmake . -G "Visual Studio 15 2017 Win64"

-- The C compiler identification is MSVC 19.11.25547.0
-- The CXX compiler identification is MSVC 19.11.25547.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Boost version: 1.65.1
-- Found the following Boost libraries:
--   filesystem
--   system
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/theo/Desktop/cpp_zia/modules/mod_autoindex

So the solution generation seems to work fine, but after that, when I try to build MSBuild mod_autoindex.sln i get the following error

LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc141-mt-gd-1_65_1.lib' [C:\Users\theo\
Desktop\cpp_zia\modules\mod_autoindex\mod_autoindex.vcxproj]

@update here is my current cmake

cmake_minimum_required(VERSION 3.8)

project(mod_autoindex)

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIRECTORY}")
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}")

set(BOOST_ROOT "C:/Program Files (x86)/boost/boost_1_65_1")
set(Boost_ADDITIONAL_VERSIONS 1.65.1)

set(BOOST_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost COMPONENTS filesystem REQUIRED)

if (UNIX)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra")
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
else()
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()

include_directories(${Boost_INCLUDE_DIR})
include_directories("../../include")
include_directories("../../include/sza")
include_directories("./include")


file(GLOB_RECURSE CPP_SRCS ${CMAKE_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE HEADERS ${CMAKE_SOURCE_DIR}/include/*.hpp)
MESSAGE( STATUS "BOOST libraries: " ${Boost_LIBRARIES} )

add_library(${PROJECT_NAME} SHARED ${CPP_SRCS} ${HEADERS})
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})

Upvotes: 2

Views: 9650

Answers (1)

vre
vre

Reputation: 6734

Many Boost libraries indeed are header only, but filesystem is not.

Instead of doing things manually I would use the CMake way of adding library dependencies by using the appropriate find_package module:

set(BOOST_ROOT "C:/Program Files (x86)/boost/boost_1_65_1")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost COMPONENTS filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
...
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})

Boost binaries for your compiler can be downloaded at https://sourceforge.net/projects/boost/files/boost-binaries/

If CMake does not find your Boost installation (CMake 3.10.2 versions FindBoost.cmake module does know about versions up to Boost 1.65.1) you can try to add before the find_package call

set(Boost_ADDITIONAL_VERSIONS 1.66.0) 

but

Boost changed its naming scheme starting from version 1.66.0. CMake up to version 3.10.2 does not know this scheme and therefore cannot handle it. You need to use Boost 1.65.1 instead.

Edit according to the comment by @ComicSansMS:

Do not hardcode the Boost path to your CMakeLists.txt instead set it per environment variable BOOST_ROOT or provide it as argument to your CMake call.

So go to your project path (the path where your CMakeLists.txt is stored)

mkdir build
cd build

and either do

set BOOST_ROOT=C:\Program Files (x86)\boost\boost_1_65_1
cmake .. -G "Visual Studio 15 2017"  

or call

cmake .. -G "Visual Studio 15 2017" -DBOOST_ROOT="C:\Program Files (x86)\boost\boost_1_65_1"

Later you can use the buildmode of CMake to build your entire project

cmake --build . --target ALL_BUILD --config Release -- /nologo /verbosity:minimal /maxcpucount

Upvotes: 3

Related Questions