A small note about static linking Boost, so as not to forget.
Initial data:
- OS Windows
- MSVC 2017 64bit
- Boost 1.68.0
- CMake project
An example will be shown in the simplest version without special variable settings. Maximum default.
Step 1
Скачиваем boost библиотеку и куда-нибудь её распаковываем. Место распаковки не принципиально.
Step 2
We only carry out two commands to the unpacking boost directory.
To build the engine
- bootstrap.bat vc141
To build and install libraries directly
- .\b2 toolset=msvc-14.1 --address-model=64 --link=static --variant=debug --variant=release stage install
In this case, a static build of the boost in the release and debug versions will be performed.
All files will be copied to the following directory.
- C:\Boost
Step 3
Configuration of CMakeLists.txt
- cmake_minimum_required (VERSION 3.8)
- project(MyProject)
- set(CMAKE_CXX_STANDARD 17)
- set(Boost_USE_STATIC_LIBS ON)
- find_package(Boost 1.68 COMPONENTS program_options)
- set(SOURCE_FILES
- main.cpp
- App.cpp
- App.h)
- if(Boost_FOUND)
- include_directories(${Boost_INCLUDE_DIRS})
- add_executable(MyProject${SOURCE_FILES})
- target_link_libraries(MyProject${Boost_LIBRARIES})
- endif()
Сделал всё по-как у вас, но выдаёт ошибку
[build] LINK : fatal error LNK1104: не удается открыть файл "libboost_locale-vc142-mt-gd-x64-1_74.lib"
Хоть убей, не могу понять в чём дело и всё... :(
Ошибка
часто возникает, когда компоновщик не может найти или открыть файл библиотеки. В вашем случае, это файл из библиотеки Boost для C++.Шаги для решения проблемы
Проверка установки Boost
Пересборка Boost (если нужно)
Проверка наличия файла