# cannot find -lboost\_filesystem

**URL:** <https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212>\
**Category:** Usage\
**Tags:** gen:makefiles\
**Created:** [October 6, 2021, 6:18am UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212 "2021-10-06T06:18:07Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![shayan\_Hojati](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shayan_hojati/32/1851_2.png) [@shayan\_Hojati](https://discourse.cmake.org/u/shayan_Hojati)\
**Post date:** [October 6, 2021, 6:18am UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/1 "2021-10-06T06:18:07Z")

</div>

I found a code from GitHub whose **CMakeLists .txt** file looks like this:

```cmake
cmake_minimum_required(VERSION 3.7)
project(obj_loader)

execute_process(COMMAND python -c "import tensorflow; print(tensorflow.sysconfig.get_include())" OUTPUT_VARIABLE Tensorflow_default_INCLUDE_DIRS)
set(Tensorflow_INCLUDE_DIRS "${Tensorflow_default_INCLUDE_DIRS}" CACHE PATH "Tensorflow include path")
include_directories(${Tensorflow_INCLUDE_DIRS})

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES obj_loader.cpp)
add_library(obj_loader SHARED ${SOURCE_FILES})
target_link_libraries(obj_loader boost_filesystem)

```

I get the following error when I run the mingw32-make command

```auto
[50%] Building CXX object CMakeFiles/obj_loader.dir/obj_loader.cpp.obj
[100%] Linking CXX shared library libobj_loader.dll
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_filesystem
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [CMakeFiles\obj_loader.dir\build.make:99: libobj_loader.dll] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/obj_loader.dir/all] Error 2
mingw32-make: *** [Makefile:90: all] Error 2

```

What is the `-lboost_filesystem` error related to?  
Thank you in advance

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [October 6, 2021, 12:19pm UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/2 "2021-10-06T12:19:28Z")

</div>

> [@shayan\_Hojati](#):
>
> `target_link_libraries(obj_loader boost_filesystem)`

Here the code says “link to `boost_filesystem`”, but nothing indicates where this file could exist. I would recommend that the code instead do:

```cmake
find_package(Boost REQUIRED COMPONENTS filesystem)
target_link_libraries(obj_loader Boost::filesystem)

```

CMake will end up with an error if Boost cannot be found and it can be cycled at configure rather than build/link time.

---

<div class="post-metadata">

**Author:** ![shayan\_Hojati](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shayan_hojati/32/1851_2.png) [@shayan\_Hojati](https://discourse.cmake.org/u/shayan_Hojati)\
**Post date:** [October 7, 2021, 8:46am UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/3 "2021-10-07T08:46:15Z")

</div>

Thank you  
I used alternative codes, however, despite finding the boost, it gives me the following error:

– The C compiler identification is GNU 10.3.0  
– The CXX compiler identification is GNU 10.3.0  
– Detecting C compiler ABI info  
– Detecting C compiler ABI info - done  
– Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - skipped  
– Detecting C compile features  
– Detecting C compile features - done  
– Detecting CXX compiler ABI info  
– Detecting CXX compiler ABI info - done  
– Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe - skipped  
– Detecting CXX compile features  
– Detecting CXX compile features - done  
CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.21/Modules/FindPackageHandleStandardArgs.cmake:438 (message):  
The package name passed to `find_package_handle_standard_args` (Boost) does  
not match the name of the calling package (BOOST). This can lead to  
problems in calling code that expects `find_package` result variables  
(e.g., `_FOUND`) to follow a certain pattern.  
Call Stack (most recent call first):  
C:/Program Files/CMake/share/cmake-3.21/Modules/FindBoost.cmake:2360 (find\_package\_handle\_standard\_args)  
CMakeLists.txt:5 (find\_package)  
This warning is for project developers. Use -Wno-dev to suppress it.

– Found Boost: C:/Program Files/boost\_1\_70\_0/boost\_1\_70\_0 (found version “1.70.0”)  
– Configuring done  
CMake Warning:  
Value of Tensorflow\_INCLUDE\_DIRS contained a newline; truncating

**CMake Error at CMakeLists.txt:14 (add\_library):  
Target “obj\_loader” links to target “BOOST::filesystem” but the target was  
not found. Perhaps a find\_package() call is missing for an IMPORTED  
target, or an ALIAS target is missing?**

– Generating done  
CMake Generate step failed. Build files cannot be regenerated correctly.

**Enviroment Variables :**  
BOOST\_ROOT : C:\Program Files\boost\_1\_70\_0\boost\_1\_70\_0  
BOOST\_INCLUDEDIR : C:\Program Files\boost\_1\_70\_0\boost\_1\_70\_0  
BOOST\_LIBRARYDIR : C:\Program Files\boost\_1\_70\_0\boost\_1\_70\_0\stage\lib

**Installed :**

- Windows 10 64 bit
- cmake version 3.21.3
- gcc (Rev5, Built by MSYS2 project) 10.3.0
- Boost\_1\_70\_0

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [October 7, 2021, 12:08pm UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/4 "2021-10-07T12:08:02Z")

</div>

Could you share the `find_package()` call you actually used?

---

<div class="post-metadata">

**Author:** ![shayan\_Hojati](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shayan_hojati/32/1851_2.png) [@shayan\_Hojati](https://discourse.cmake.org/u/shayan_Hojati)\
**Post date:** [October 8, 2021, 6:14am UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/5 "2021-10-08T06:14:35Z")

</div>

These are the changes I made to the CMakeList.txt file

cmake\_minimum\_required(VERSION 3.7)  
project(obj\_loader)

cmake\_policy(SET CMP0074 NEW)  
find\_package(BOOST REQUIRED COMPONENTS filesystem)

execute\_process(COMMAND python -c “import tensorflow; print(tensorflow.sysconfig.get\_include())” OUTPUT\_VARIABLE Tensorflow\_default\_INCLUDE\_DIRS)  
set(Tensorflow\_INCLUDE\_DIRS “${Tensorflow\_default\_INCLUDE\_DIRS}” CACHE PATH “Tensorflow include path”)  
include\_directories(${Tensorflow\_INCLUDE\_DIRS})

set(CMAKE\_CXX\_STANDARD 11)

set(SOURCE\_FILES obj\_loader.cpp)  
add\_library(obj\_loader SHARED ${SOURCE\_FILES})  
target\_link\_libraries(obj\_loader BOOST::filesystem)

---

<div class="post-metadata">

**Author:** ![shayan\_Hojati](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shayan_hojati/32/1851_2.png) [@shayan\_Hojati](https://discourse.cmake.org/u/shayan_Hojati)\
**Post date:** [October 8, 2021, 9:48am UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/6 "2021-10-08T09:48:51Z")

</div>

I reinstall boost 1.70 with the help of [Installing boost libraries for GCC (MinGW) on Windows](https://gist.github.com/sim642/29caef3cc8afaa273ce6#project-setup)  
now my error has changed to :

– The C compiler identification is GNU 10.3.0  
– The CXX compiler identification is GNU 10.3.0  
– Detecting C compiler ABI info  
– Detecting C compiler ABI info - done  
– Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - skipped  
– Detecting C compile features  
– Detecting C compile features - done  
– Detecting CXX compiler ABI info  
– Detecting CXX compiler ABI info - done  
– Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe - skipped  
– Detecting CXX compile features  
– Detecting CXX compile features - done  
– Found Boost 1.70.0 at C:/Program Files/boost/lib/cmake/Boost-1.70.0  
– Requested configuration: QUIET REQUIRED COMPONENTS filesystem  
– Found boost\_headers 1.70.0 at C:/Program Files/boost/lib/cmake/boost\_headers-1.70.0  
– Found boost\_filesystem 1.70.0 at C:/Program Files/boost/lib/cmake/boost\_filesystem-1.70.0  
– No suitable boost\_filesystem variant has been identified!  
– libboost\_filesystem-mgw103-mt-d-x32-1\_70.a (32 bit, need 64)  
– libboost\_filesystem-mgw103-mt-d-x64-1\_70.a (mgw103, detected mgw10, set Boost\_COMPILER to override)  
– libboost\_filesystem-mgw103-mt-x32-1\_70.a (32 bit, need 64)  
– libboost\_filesystem-mgw103-mt-x64-1\_70.a (mgw103, detected mgw10, set Boost\_COMPILER to override)  
**CMake Error at C:/Program Files/boost/lib/cmake/Boost-1.70.0/BoostConfig.cmake:95 (find\_package):  
Found package configuration file:**

```
C:/Program Files/boost/lib/cmake/boost_filesystem-1.70.0/boost_filesystem-config.cmake

```

but it set boost\_filesystem\_FOUND to FALSE so package “boost\_filesystem” is  
considered to be NOT FOUND. Reason given by package:

No suitable build variant has been found.

Call Stack (most recent call first):  
C:/Program Files/boost/lib/cmake/Boost-1.70.0/BoostConfig.cmake:124 (boost\_find\_dependency)  
C:/Program Files/CMake/share/cmake-3.21/Modules/FindBoost.cmake:594 (find\_package)  
CMakeLists.txt:5 (find\_package)

– Configuring incomplete, errors occurred!  
See also “D:/project/bmvc-code/obj\_loader/cmake-build-release/CMakeFiles/CMakeOutput.log”.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [October 8, 2021, 11:23am UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/7 "2021-10-08T11:23:24Z")

</div>

> [@shayan\_Hojati](#):
>
> find\_package(BOOST REQUIRED COMPONENTS filesystem)

> [@shayan\_Hojati](#):
>
> target\_link\_libraries(obj\_loader BOOST::filesystem)

It should be `Boost`, not `BOOST`. The `find_package` works because you’re on Windows and the case-insensitive file name behaviors make it work. However, CMake is case-sensitive and the targets it makes are named `Boost::`. Using the right casing will also resolve the warning about the case mismatch you received.

---

<div class="post-metadata">

**Author:** ![shayan\_Hojati](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shayan_hojati/32/1851_2.png) [@shayan\_Hojati](https://discourse.cmake.org/u/shayan_Hojati)\
**Post date:** [October 8, 2021, 3:19pm UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/8 "2021-10-08T15:19:17Z")

</div>

![CMake_Error](https://discourse.cmake.org/uploads/default/original/2X/d/d7f5b2440b5d7e0a3945bffdfde621c49490e9d7.png)

Ben I did as you said, but I still have the same problem. Please take a look at the picture

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [October 8, 2021, 5:01pm UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/9 "2021-10-08T17:01:41Z")

</div>

The output is saying that the Boost you have is not suitable. It found debug (the `-d` libraries) and release libraries. Of those, the 32bit ones are unsuitable (expected) and the `x64` ones are built using MSVC which is not compatible with MinGW. You’ll need a Boost built with the MinGW toolchain.

Whoops, they are MinGW, just not the right version. They are MinGW 10.0 when you have 10.3. I think setting `Boost_COMPILER` to `mgw10` might work?

---

<div class="post-metadata">

**Author:** ![shayan\_Hojati](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shayan_hojati/32/1851_2.png) [@shayan\_Hojati](https://discourse.cmake.org/u/shayan_Hojati)\
**Post date:** [October 9, 2021, 9:11am UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/13 "2021-10-09T09:11:07Z")

</div>

> [@ben.boeckel](#):
>
> They are MinGW 10.0 when you have 10.3

I tested Boost\_COMPILER with gcc and mingw / numbers 10 and 103.  
Only error :  
**- libboost\_filesystem-mgw103-mt-d-x64-1\_70.a (mgw103, detected mgw10, set Boost\_COMPILER to override)**  
converted to  
**- libboost\_filesystem-mgw103-mt-x64-1\_70.a (mgw103, Boost\_COMPILER = gcc10).**

I followed the error. Cannot set **\_\_boost\_variants** and **\_\_boost\_configs** in **boost\_filesystem-config.cmake**. This probably goes back to the same issue you mentioned, but I have **gcc (Rev5, Built by MSYS2 project) 10.3.0 installed** on the system and I also installed **boost 1.70 with the same gcc** , so where does this mismatch come from?

> **Boost\_filesystem-config.cmake**
>
> ```cmake
> # Generated by Boost 1.70.0
> 
> if(TARGET Boost::filesystem)
> return()
> endif()
> 
> message(STATUS "Found boost_filesystem ${boost_filesystem_VERSION} at ${boost_filesystem_DIR}")
> 
> # Compute the include and library directories relative to this file.
> get_filename_component(_BOOST_CMAKEDIR "${CMAKE_CURRENT_LIST_DIR}/../" ABSOLUTE)
> get_filename_component(_BOOST_INCLUDEDIR "${_BOOST_CMAKEDIR}/../../include/boost-1_70/" ABSOLUTE)
> get_filename_component(_BOOST_LIBDIR "${_BOOST_CMAKEDIR}/../" ABSOLUTE)
> 
> # Create imported target Boost::filesystem
> add_library(Boost::filesystem UNKNOWN IMPORTED)
> 
> set_target_properties(Boost::filesystem PROPERTIES
> INTERFACE_INCLUDE_DIRECTORIES "${_BOOST_INCLUDEDIR}"
> INTERFACE_COMPILE_DEFINITIONS "BOOST_ALL_NO_LIB"
> )
> 
> include(${CMAKE_CURRENT_LIST_DIR}/../BoostDetectToolset-1.70.0.cmake)
> 
> if(Boost_DEBUG)
> message(STATUS "Scanning ${CMAKE_CURRENT_LIST_DIR}/libboost_filesystem-variant*.cmake")
> endif()
> 
> file(GLOB __boost_variants "${CMAKE_CURRENT_LIST_DIR}/libboost_filesystem-variant*.cmake")
> 
> macro(_BOOST_SKIPPED fname reason)
> if(Boost_DEBUG)
> message(STATUS " ... skipped ${fname} (${reason})")
> endif()
> list(APPEND __boost_skipped "${fname} (${reason})")
> endmacro()
> 
> foreach(f IN LISTS __boost_variants)
> if(Boost_DEBUG)
> message(STATUS " Including ${f}")
> endif()
> include(${f})
> endforeach()
> 
> unset(_BOOST_LIBDIR)
> unset(_BOOST_INCLUDEDIR)
> unset(_BOOST_CMAKEDIR)
> 
> get_target_property(__boost_configs Boost::filesystem IMPORTED_CONFIGURATIONS)
> 
> if( __boost_variants AND NOT__ boost_configs)
> message(STATUS "No suitable boost_filesystem variant has been identified!")
> if(NOT Boost_DEBUG)
> foreach(s IN LISTS __boost_skipped)
> message(STATUS " ${s}")
> endforeach()
> endif()
> set(boost_filesystem_FOUND 0)
> set(boost_filesystem_NOT_FOUND_MESSAGE "No suitable build variant has been found.")
> unset(__boost_skipped)
> unset(__boost_configs)
> unset(__boost_variants)
> unset(_BOOST_FILESYSTEM_DEPS)
> return()
> endif()
> 
> unset(__boost_skipped)
> unset(__boost_configs)
> unset(__boost_variants)
> 
> if(_BOOST_FILESYSTEM_DEPS)
> list(REMOVE_DUPLICATES _BOOST_FILESYSTEM_DEPS)
> message(STATUS "Adding boost_filesystem dependencies: ${_BOOST_FILESYSTEM_DEPS}")
> endif()
> 
> foreach(dep_boost_filesystem IN LISTS _BOOST_FILESYSTEM_DEPS)
> set(_BOOST_QUIET)
> if(boost_filesystem_FIND_QUIETLY)
> set(_BOOST_QUIET QUIET)
> endif()
> set(_BOOST_REQUIRED)
> if(boost_filesystem_FIND_REQUIRED)
> set(_BOOST_REQUIRED REQUIRED)
> endif()
> get_filename_component(_BOOST_CMAKEDIR "${CMAKE_CURRENT_LIST_DIR}/../" ABSOLUTE)
> find_package(boost_${dep_boost_filesystem} 1.70.0 EXACT CONFIG ${_BOOST_REQUIRED} ${_BOOST_QUIET} HINTS ${_BOOST_CMAKEDIR})
> set_property(TARGET Boost::filesystem APPEND PROPERTY INTERFACE_LINK_LIBRARIES Boost::${dep_boost_filesystem})
> unset(_BOOST_QUIET)
> unset(_BOOST_REQUIRED)
> unset(_BOOST_CMAKEDIR)
> if(NOT boost_${dep_boost_filesystem}_FOUND)
> set(boost_filesystem_FOUND 0)
> set(boost_filesystem_NOT_FOUND_MESSAGE "A required dependency, boost_${dep_boost_filesystem}, has not been found.")
> unset(_BOOST_FILESYSTEM_DEPS)
> return()
> endif()
> endforeach()
> 
> unset(_BOOST_FILESYSTEM_DEPS)
> 
> ```

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [October 10, 2021, 8:52pm UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/14 "2021-10-10T20:52:09Z")

</div>

I’m sorry, this is out of my Boost knowledge. I recommend asking the `boost-cmake` team what might be up here.

---

<div class="post-metadata">

**Author:** ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)\
**Post date:** [October 11, 2021, 5:53am UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/15 "2021-10-11T05:53:58Z")

</div>

@shayan_Hojati and you have exact same error message when setting `Boost_COMPILER` to `mgw103`?

---

<div class="post-metadata">

**Author:** ![shayan\_Hojati](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shayan_hojati/32/1851_2.png) [@shayan\_Hojati](https://discourse.cmake.org/u/shayan_Hojati)\
**Post date:** [October 11, 2021, 9:04am UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/16 "2021-10-11T09:04:48Z")

</div>

Thank you so much for following up 😉

---

<div class="post-metadata">

**Author:** ![shayan\_Hojati](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shayan_hojati/32/1851_2.png) [@shayan\_Hojati](https://discourse.cmake.org/u/shayan_Hojati)\
**Post date:** [October 11, 2021, 9:21am UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/17 "2021-10-11T09:21:53Z")

</div>

Yes . I had to reinstall Boost, but this time I changed both the boost version and the gcc version!  
As my impression, the problem may have been with MSYS2, however, for those who refer to this topic later, I used Boost 1.77 and gcc 8.1.0, and it worked for me.

But now I have another problem!!!

In the CMakeList .txt file where I put the line :

> execute\_process (COMMAND python -c “import tensorflow; print (tensorflow.sysconfig.get\_include ())” OUTPUT\_VARIABLE Tensorflow\_default\_INCLUDE\_DIRS)

Returns the path of the tensorflow, but when I want to use op.h,OpKernel in the objectLoder.cpp file, I find the following error :

> CMakeFiles\obj\_loader.dir/objects.a(obj\_loader.cpp.obj):obj\_loader.cpp:(.text$\_ZN11ObjLoaderOpD1Ev[\_ZN11ObjLoaderOpD1Ev]+0x46): undefined reference to `tensorflow::OpKernel::~OpKernel()

And my addressing type in, objectloader.cpp is as follows :

> #include “tensorflow/core/framework/op.h”  
> #include “tensorflow/core/framework/op\_kernel.h”  
> #include “tensorflow/core/framework/shape\_inference.h”

Where do you think the problem comes from?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [October 11, 2021, 11:40am UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/18 "2021-10-11T11:40:18Z")

</div>

That gets the _include_ directories. You also need to link to TensorFlow to get its symbols at link time.

---

<div class="post-metadata">

**Author:** ![shayan\_Hojati](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shayan_hojati/32/1851_2.png) [@shayan\_Hojati](https://discourse.cmake.org/u/shayan_Hojati)\
**Post date:** [October 11, 2021, 2:19pm UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/19 "2021-10-11T14:19:33Z")

</div>

Sorry, I did not understand what you meant

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [October 11, 2021, 2:53pm UTC](https://discourse.cmake.org/t/cannot-find-lboost-filesystem/4212/20 "2021-10-11T14:53:40Z")

</div>

Just because you can include headers does not mean that you’ve done everything that is needed. I don’t know TensorFlow, so you’ll have to look there for what exactly is needed, but you need to ask for the libraries that you need to link against (probably similar mechanisms to getting its include directories).
