0
votes

I used Cmake gui and the FindBoost module to add Boost as a dependency in my visual studio 2010 c++ project. I set the parameter that tells FindBoost to use the win32 thread library instead of pthread (because I'm running on windows). When i build my code, all the calls to boost libraries compile fine, but boost itself is having a compile error. its failing on

boost\thread\pthread\mutex.hpp line 11 cannot open include file: 'pthread.h': No such file or directory

If I could make it use the win32 library, the mutex.hpp (and all the other files) dont call pthread.h How do I build so that it uses boost\thread\win32 ?

here is the section of my cmakelists.txt

# include boost

set(BOOST_ROOT "E:/boost_1_58_0/boost_1_58_0")

add_definitions( -DBOOST_ALL_NO_LIB )

find_package(Boost COMPONENTS thread system)

if(Boost_FOUND)

    message(STATUS "Boost was found, Success!")

    # telling it to use win32 threads not pthreads

      set(Boost_THREADAPI "win32") 

      INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})

      LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})

endif()

CMake comes with a module called FindBoost which i used, and it correctly found the boost directory and set the following

Boost_INCLUDE_DIR
E:/boost_1_58_0/boost_1_58_0/

Boost_LIBRARY_DIR
E:/boost_1_58_0/boost_1_58_0/stage/lib

Boost_SYSTEM_LIBRARY_DEBUG
E:/boost_1_58_0/boost_1_58_0/stage/lib/boost_system-vc100-mt-gd-1_58.lib

Boost_SYSTEM_LIBRARY_RELEASE
E:/boost_1_58_0/boost_1_58_0/stage/lib/boost_system-vc100-mt-1_58.lib

Boost_THREAD_LIBRARY_DEBUG
E:/boost_1_58_0/boost_1_58_0/stage/lib/boost_system-vc100-mt-gd-1_58.lib

Boost_THREAD_LIBRARY_RELEASE
E:/boost_1_58_0/boost_1_58_0/stage/lib/boost_thread-vc100-mt-1_58.lib

visual studio project settings

C/C++ -> General -> Additional Include Directories:
    ...bunch of my other dependencies
    E:\boost_1_58_0\boost_1_58_0

Linker -> General -> Additional Library Directories        

E:/boost_1_58_0/boost_1_58_0/stage/lib;E:/boost_1_58_0/boost_1_58_0/stage/lib/$(Configuration);%(AdditionalLibraryDirectories)

Linker -> General -> Link Library Dependencies - No
Linker -> General -> Use LIbrary Dependency Inputs - No
Linker -> Input -> Additional Dependencies:
    ...bunch of my other .libs
    boost_thread.lib
    boost_system.lib
1
did you bootstrap boost before you used it?Richard Hodges
yea i built boost using bootstrap and b2 with the msvc-10.0 settings. my project's calls to the boost libraries are compiling. its just the boost itself, which i dont understand. i know the binaries are already built and i know you still need headers to say what is available in those binaries. i guess its just picking the wrong headers.mobooya
Are you cross-compiling? You don't need to set Boost_THREADAPI if you're on Windows. How do you generate VS project file from this CMakeLists? What global macros do you see in the VS project file (project or cpp settings)?Igor R.
im not cross compiling today, but a few months from now i will. I generate the VS project using Cmake-gui. I will edit the main post to list the cmake and VS project settingsmobooya

1 Answers

1
votes

I fixed the error but I had try what I call the "dumb" way. The "smart" way didnt work. Smart way was reviewing several times the cmakelists code and the visual studio include library settings. i even did a clean and rebuild boost using b2 and manually set threading=multi and link=static because i thought maybe the library just wasnt built correct.

Finally i gave up and tried the dumb way: I cut and pasted the pthread folder and moved it somewhere else, so that it was no longer in the boost/thread folder, only the win32 folder.
I wish i tried it so long ago, because i didnt think that the compilation error would be due to my project's code, but rather an environment setting in the include and linking. But sure enough i got an error showing that in one of my project's files i was directly trying to include that mutex.hpp from the pthread folder. i didnt write this code (its open source) so i couldnt have exactly known, but still i want to slap myself

#include <boost/thread.hpp>
#include <boost/thread/pthread/mutex.hpp>

changing pthread to win32 made the error go away.