1

What I have missed?

I can't build a simple project using CMake + vc142 + boost 1.71.1 on a windows host. What is funny, this project remotely built on WSL Debian compiles and runs correctly. Boost installation is correct, the new Vcproj with additional includes and libs linked to ENV{BOOST_ROOT} and ENV{BOOST_INCLUDEDIR} dirs builds and runs correctly.

[Edit] Adding set(Boost_USE_STATIC_LIBS ON) to cmake works, as @vre said. But using this stackoverflow.com/questions/28887680/… ends up with: Linking success, but in runtime it ends with: "Process finished with exit code -1073741515 (0xC0000135)"

[Edit2] Using prebuilt boost from: https://sourceforge.net/projects/boost/files/boost-binaries/1.71.0/ gives same results;

[Edit3] Effect on WSL Debian, with set (Boost_USE_STATIC_LIBS OFF CACHE BOOL "use static libraries from Boost") :

/tmp/tmp.75syfbaPik/cmake-build-debug-wsl-debian/untitled
Hello, World!=D
terminate called after throwing an instance of 'boost::filesystem::filesystem_error'
  what():  boost::filesystem::file_size: No such file or directory: "c:\boost_1_71_0.7z"

Process finished with exit code 134

[SOLUTION] Add Boost ".../stage/lib" ( f.e. C:\boost_1_71_0\stage|lib) to Env PATH;

Statically linking boost use:

set(Boost_USE_STATIC_LIBS ON)

Dynamicall linking boost use:

if (WIN32)
    # disable autolinking in boost
    add_definitions( -DBOOST_ALL_NO_LIB )

    # force all boost libraries to dynamic link (we already disabled
    # autolinking, so I don't know why we need this, but we do!)
    add_definitions( -DBOOST_ALL_DYN_LINK )
endif()
set (Boost_USE_STATIC_LIBS OFF CACHE BOOL "use static libraries from Boost")

Helpfull

CMake:

cmake_minimum_required(VERSION 3.13)
project(untitled
        VERSION 0.0.0
        LANGUAGES CXX
        )
set(CMAKE_CXX_STANDARD 17)

set(Boost_DEBUG 1)
find_package(Boost 1.71.0 REQUIRED COMPONENTS filesystem)

add_executable(untitled main.cpp)
target_link_libraries(untitled Boost::filesystem)

main.cpp:

#include <iostream>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;

int main() {
    std::cout << "Hello, World!=D" << std::endl;
    std::cout << "c:\\boost_1_71_0.7z" << " " << file_size("c:\\boost_1_71_0.7z") << '\n';
    return 0;
}

CMake log from Clion:

"C:\Program Files\JetBrains\CLion 2019.2.3\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - NMake Makefiles" D:\untitled
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1446 ] _boost_TEST_VERSIONS = "1.71.0;1.71"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1447 ] Boost_USE_MULTITHREADED = "TRUE"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1448 ] Boost_USE_STATIC_LIBS = <unset>
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1449 ] Boost_USE_STATIC_RUNTIME = <unset>
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1450 ] Boost_ADDITIONAL_VERSIONS = <unset>
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1451 ] Boost_NO_SYSTEM_PATHS = <unset>
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1520 ] BOOST_ROOT = <unset>
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1521 ] ENV{BOOST_ROOT} = "C:\boost_1_71_0"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1522 ] BOOST_INCLUDEDIR = <unset>
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1523 ] ENV{BOOST_INCLUDEDIR} = "C:\boost_1_71_0"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1524 ] BOOST_LIBRARYDIR = <unset>
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1525 ] ENV{BOOST_LIBRARYDIR} = "C:\boost_1_71_0\stage\lib"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1613 ] location of version.hpp: C:/boost_1_71_0/boost/version.hpp
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1653 ] Boost_VERSION = "107100"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1654 ] Boost_VERSION_STRING = "1.71.0"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1655 ] Boost_VERSION_MACRO = "107100"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1656 ] Boost_VERSION_MAJOR = "1"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1657 ] Boost_VERSION_MINOR = "71"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1658 ] Boost_VERSION_PATCH = "0"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1659 ] Boost_VERSION_COUNT = "3"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1676 ] Boost_LIB_PREFIX = ""
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1677 ] Boost_NAMESPACE = "boost"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:787 ] _boost_COMPILER = "-vc142;-vc141;-vc140" (guessed)
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1713 ] _boost_MULTITHREADED = "-mt"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1790 ] _boost_ARCHITECTURE_TAG = "-x32" (detected)
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1794 ] _boost_RELEASE_ABI_TAG = "-"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1795 ] _boost_DEBUG_ABI_TAG = "-gd"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1855 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = "C:/boost_1_71_0/stage/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1856 ] _boost_LIBRARY_SEARCH_DIRS_DEBUG = "C:/boost_1_71_0/stage/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:2040 ] Searching for FILESYSTEM_LIBRARY_RELEASE: boost_filesystem-vc142-mt-x32-1_71;boost_filesystem-vc142-mt-x32;boost_filesystem-vc142-mt;boost_filesystem-vc141-mt-x32-1_71;boost_filesystem-vc141-mt-x32;boost_filesystem-vc141-mt;boost_filesystem-vc140-mt-x32-1_71;boost_filesystem-vc140-mt-x32;boost_filesystem-vc140-mt;boost_filesystem-mt-x32-1_71;boost_filesystem-mt-x32;boost_filesystem-mt;boost_filesystem-mt;boost_filesystem
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:646 ] Boost_LIBRARY_DIR_RELEASE = "C:/boost_1_71_0/stage/lib"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:648 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = "C:/boost_1_71_0/stage/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:2095 ] Searching for FILESYSTEM_LIBRARY_DEBUG: boost_filesystem-vc142-mt-gd-x32-1_71;boost_filesystem-vc142-mt-gd-x32;boost_filesystem-vc142-mt-gd;boost_filesystem-vc141-mt-gd-x32-1_71;boost_filesystem-vc141-mt-gd-x32;boost_filesystem-vc141-mt-gd;boost_filesystem-vc140-mt-gd-x32-1_71;boost_filesystem-vc140-mt-gd-x32;boost_filesystem-vc140-mt-gd;boost_filesystem-mt-gd-x32-1_71;boost_filesystem-mt-gd-x32;boost_filesystem-mt-gd;boost_filesystem-mt;boost_filesystem
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:646 ] Boost_LIBRARY_DIR_DEBUG = "C:/boost_1_71_0/stage/lib"
-- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:648 ] _boost_LIBRARY_SEARCH_DIRS_DEBUG = "C:/boost_1_71_0/stage/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH"
-- Configuring done
-- Generating done
-- Build files have been written to: D:/untitled/cmake-build-debug

[Finished]

Build log:

====================[ Build | all | Debug ]=====================================
"C:\Program Files\JetBrains\CLion 2019.2.3\bin\cmake\win\bin\cmake.exe" --build D:\untitled\cmake-build-debug --target all --
[ 50%] Linking CXX executable untitled.exe
LINK Pass 1: command "C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1423~1.281\bin\Hostx86\x86\link.exe /nologo @CMakeFiles\untitled.dir\objects1.rsp /out:untitled.exe /implib:untitled.lib /pdb:D:\untitled\cmake-build-debug\untitled.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:console C:\boost_1_71_0\stage\lib\boost_filesystem-vc142-mt-gd-x32-1_71.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\untitled.dir/intermediate.manifest CMakeFiles\untitled.dir/manifest.res" failed (exit code 1104) with the following output:
LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc142-mt-gd-x32-1_71.lib'
NMAKE : fatal error U1077: '"C:\Program Files\JetBrains\CLion 2019.2.3\bin\cmake\win\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.

Lib exists screenshot

boost_filesystem-vc142-mt-gd-x32-1_71 exists in lib dir

Rockedge
  • 11
  • 4
  • [maybe this helps](https://stackoverflow.com/questions/13042561/fatal-error-lnk1104-cannot-open-file-libboost-system-vc110-mt-gd-1-51-lib) – dorKKnight Oct 11 '19 at 10:57
  • For me it looks like you did not built the static boost libraries (`libboost_filesystem...`),but only the DLL's (`boost_filesystem...`). Download a prebuilt windows version from here (it's the official Boost download area): https://sourceforge.net/projects/boost/files/boost-binaries/1.71.0/boost_1_71_0-msvc-14.2-32.exe/download or the 64 bit version if needed. – vre Oct 11 '19 at 11:16
  • @vre plz look at screenshot - "Lib exists screenshot" lib C:\boost_1_71_0\stage\lib\libboost_filesystem-vc142-mt-gd-x32-1_71.lib exists with size 5725KB – Rockedge Oct 11 '19 at 11:30
  • @dorKKnight it's for vcproj, vcxproj, works perfectly, but i would like to work with cmake proj using Clion. – Rockedge Oct 11 '19 at 11:30
  • Absolute path to the library, **passed to the linker**, is `C:\boost_1_71_0\stage\lib\boost_filesystem-vc142-mt-gd-x32-1_71.lib`. It doesn't contain `lib` file prefix and seems to be non-existed file. Not sure why... – Tsyvarev Oct 11 '19 at 11:33
  • @Rockedge the path shown in error is **C:\boost_1_71_0\stage\lib\boost_filesystem-vc142-mt-gd-x32-1_71.lib** But in the screenshot that you have shared; it is like **C:\boost_1_71_0\stage\lib** so i guess that either CLion should know the correct path of the lib files OR modify the CMake file so it picks up the correct path of the libs. – dorKKnight Oct 11 '19 at 11:41
  • 1
    Then you need to add `set(Boost_USE_STATIC_LIBS ON)` to your CMakeLists.txt before the find_package call. This variable defaults to `OFF`. Delete the CMakeCache.txt file to make sure it is considered. – vre Oct 11 '19 at 11:50
  • @dorKKnight i've just uploaded screenshot that shows boost_filesystem-vc142-mt-gd-x32-1_71 exists in this directory. I think it's not a Clion problem, running cmake from cmd gives the same results. Cmake module FindGtest knows the path to boost libs, plz look at the cmake log: -- [ C:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1525 ] ENV{BOOST_LIBRARYDIR} = "C:\boost_1_71_0\stage\lib" – Rockedge Oct 11 '19 at 11:58
  • @vre it works set(Boost_USE_STATIC_LIBS ON), thx :) But how to link boost as dynamics? – Rockedge Oct 11 '19 at 12:02
  • Using this https://stackoverflow.com/questions/28887680/linking-boost-library-with-boost-use-static-lib-off-on-windows ends up with: Linking success, but runing it ends with: "Process finished with exit code -1073741515 (0xC0000135)" – Rockedge Oct 11 '19 at 12:13
  • It should work the way you tried out of the box for dynamic link libraries. Can you check whether you're getting the same crashes when using a prebuilt version? You may need to specify BOOST_ROOT or BOOST_DIR (`set(BOOST_ROOT C:\\my_boost_installation_dir)` and delete the CMakeCache.txt file again. – vre Oct 11 '19 at 12:37
  • @vre I thought it should work, but it doesn't. On WSL Debian everything works fine out of the box. On 2nd pc with mingw it also works out of the box. Do you mean this: https://sourceforge.net/projects/boost/files/boost-binaries/ ? Ok, i'll try it later. Now i must do sth. else. My envs: BOOST_ROOT "C:\boost_1_71_0" BOOST_INCLUDEDIR "C:\boost_1_71_0" BOOST_LIBRARYDIR "C:\boost_1_71_0\stage\lib" I'll just change envs for prebuilts, delete CmakeCache, restart Clion, and run cmake. – Rockedge Oct 11 '19 at 12:46
  • Exactly this download link. Choose the package for your compiler and bitness and don't worry about building Boost from scratch. – vre Oct 11 '19 at 12:49
  • Using prebuilt boost ends with exactly the same effect :( – Rockedge Oct 11 '19 at 15:39
  • 1
    One last guess, can you remove the cmake_cxx_Standard setting? – vre Oct 11 '19 at 16:02
  • No difference. When removing cmake_cxx_standard Debian works, Windows: fatal error LNK1104: cannot open file 'libboost_filesystem-vc142-mt-gd-x32-1_71.lib'. Still on prebuilt. – Rockedge Oct 11 '19 at 16:25
  • 0xC0000135 means that some DLL was not found on Windows. Open the created executable in dependency_walker (32-bit) from here http://www.dependencywalker.com/ and check which one is missing from the path. Add the directory where the DLL resides to the PATH environment variable. if this happens with the dynamically linked Boost add C:\\boost_1.71.0\\lib32-msvc-16.0 to the PATH (you may need to adapt the path) – vre Oct 11 '19 at 19:26
  • @vre, Thank you very much. Adding C:\boost_1_71_0\stage\lib to PATH resolved issue when linking boost dynamically. Now everything works statically and dynamically. – Rockedge Oct 14 '19 at 13:32

0 Answers0