CMake doesn't find Boost libraries - windows

I'm trying to use a CMake script to compile a Boost-based application on Windows.
The header-only libraries work fine, but CMake fails to find the libraries (the following Boost libraries could not be found: boost_serialization). The relevant part of the CMake script is:
# Path where CMake can find additional libraries
SET(CMAKE_PREFIX_PATH Libs)
# Boost
SET(Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0")
SET(Boost_USE_STATIC_LIBS ON)
find_package(Boost REQUIRED COMPONENTS serialization)
I have a folder called "Libs" inside my project where third-party libraries such as DevIL and Boost are stored, so I set this first. It works fine for Devil and Boost header-only stuff, so I assume I should not need the BOOST_ROOT variable.
The Boost installation is the standard source distribution from boost.org which I compiled with BJam. The libraries are stored in boost_1_47_0\bin.v2\libs, and I didn't change anything in the build process.
I think it is a bit odd, that the boost_1_47_0\libs folder doesn't contain any library files but BJam files and other stuff, but that shouldn't be a problem since this seems to be the normal way to build Boost on Windows from the source.
I looked at the Debug output from the FindBoost.cmake file (I'm using the default script from CMake 2.8) and it doesn't seem to look into bin.v2. Instead it searches boost_ROOT/lib, but when I copied the content from bin.v2\libs to lib it still didn't find anything.
So what is an elegant way to find Boost that will also work on other platforms with common Boost distributions?

I would try setting BOOST_ROOT inside your CMakeLists.txt file. I know that CMake 2.8.6 will find Boost 1.47.0 when you set the Boost_ADDITIONAL_VERSIONS variable since it works for me on Windows when I have BOOST_ROOT set.
Here is what I have in one project:
set( BOOST_COMPONENTS_NEEDED serialization )
# The following verifyies that BOOST_ROOT is set properly.
if(NOT BOOST_ROOT AND NOT $ENV{BOOST_ROOT} STREQUAL "")
FILE( TO_CMAKE_PATH $ENV{BOOST_ROOT} BOOST_ROOT )
if( NOT EXISTS ${BOOST_ROOT} )
MESSAGE( STATUS ${BOOST_ROOT} " does not exist. Checking if BOOST_ROOT was a quoted string.." )
STRING( REPLACE "\"" "" BOOST_ROOT ${BOOST_ROOT} )
if( EXISTS ${BOOST_ROOT} )
MESSAGE( STATUS "After removing the quotes " ${BOOST_ROOT} " was now found by CMake" )
endif( EXISTS ${BOOST_ROOT})
endif( NOT EXISTS ${BOOST_ROOT} )
# Save the BOOST_ROOT in the cache
if( NOT EXISTS ${BOOST_ROOT} )
MESSAGE( WARNING ${BOOST_ROOT} " does not exist." )
else(NOT EXISTS ${BOOST_ROOT})
SET (BOOST_ROOT ${BOOST_ROOT} CACHE STRING "Set the value of BOOST_ROOT to point to the root folder of your boost install." FORCE)
#SET (BOOST_INCLUDEDIR ${BOOST_ROOT}/Include)
#SET (BOOST_LIBRARYDIR ${BOOST_ROOT}/lib)
endif( NOT EXISTS ${BOOST_ROOT} )
endif(NOT BOOST_ROOT AND NOT $ENV{BOOST_ROOT} STREQUAL "")
if( WIN32 AND NOT BOOST_ROOT )
MESSAGE( WARNING "Please set the BOOST_ROOT environment variable." )
endif( WIN32 AND NOT BOOST_ROOT )
set(Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0")
set(Boost_DEBUG ON)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
FIND_PACKAGE(Boost 1.47.0 COMPONENTS ${BOOST_COMPONENTS_NEEDED})
if(Boost_FOUND)
MESSAGE( STATUS "Setting up boost." )
include_directories(${Boost_INCLUDE_DIRS})
if(Boost_DEBUG)
MESSAGE( STATUS "BOOST Libraries " ${Boost_LIBRARIES} )
FOREACH(BOOST_COMPONENT ${BOOST_COMPONENTS_NEEDED})
STRING( TOUPPER ${BOOST_COMPONENT} BOOST_COMPONENT_UPCASE )
MESSAGE( STATUS "Boost " ${BOOST_COMPONENT} ": " ${Boost_${BOOST_COMPONENT_UPCASE}_LIBRARY} )
MESSAGE( STATUS "Boost " ${BOOST_COMPONENT} " Debug: " ${Boost_${BOOST_COMPONENT_UPCASE}_LIBRARY_DEBUG} )
MESSAGE( STATUS "Boost " ${BOOST_COMPONENT} " Release: " ${Boost_${BOOST_COMPONENT_UPCASE}_LIBRARY_RELEASE} )
ENDFOREACH(BOOST_COMPONENT)
endif(Boost_DEBUG)
endif(Boost_FOUND)

Well, I solved the problem, but I'm not fully satisfied with my solution.
In my opinion the problem was that BJam creates a too complex folder structure. Now I just copied the library files from "boost_1_47_0\bin.v2\libs\serialization\build\msvc-9.0\debug\link-static\threading-multi" to "boost_1_47_0\lib".
I have to do this by hand, but I'm not using that many Boost libraries, so this step is OK in my opinion. I will document my solution aside the CMake script, so other users should get along with that.

I've had a problem with this before. For some reason b2 (aka BJam) created the Boost libraries with a leading "lib".
The CMake script will not look for a file named libboost_thread.lib. It will only find boost_thread.lib. Remove the leading lib and CMake should find them.

I came here with a similar issue and just wanted to say my fix was similar, but not exactly the same.
My install prefix was C:\lib\boost\boost_1_57_0. I set a BOOST_ROOT environment variable pointing to that directory, but CMake (3.1.0) still couldn't find the headers. I realized the headers defaulted to install to C:\lib\boost\boost_1_57_0\include\boost-1_57\boost. I'm not going to run multiple versions so I just moved the final Boost directory down one and removed the boost-1_57 directory and ended up with headers here:
C:\lib\boost\boost_1_57_0\include\boost
And CMake found everything.

You can add the following option to the command line of CMake to tell CGAL to use the static Boost libraries:
-DCGAL_Boost_USE_STATIC_LIBS=true

Related

How to properly link boost with cmake

The root directory of boost ($ENV{BOOST_ROOT}) is
C:\Boost\boost_1_64_0
All compiled libraries (.dll, .lib) are in
C:\Boost\boost_1_64_0\lib64-msvc-14.1
They have both boost_xxx and libboost_xxx.
My cmake file is
set(BOOST_ROOT "$ENV{BOOST_ROOT}")
set(BOOST_LIBRARYDIR "$ENV{BOOST_ROOT}/lib64-msvc-14.1")
message("${BOOST_ROOT}")
message("${BOOST_LIBRARYDIR}")
message("${Boost_INCLUDE_DIR}")
if(MSVC)
add_definitions(-DBOOST_ALL_NO_LIB)
add_definitions(-DBOOST_ALL_DYN_LINK)
endif()
find_package(Boost 1.64.0 COMPONENTS system filesystem program_options REQUIRED)
And the output is
C:\Boost\boost_1_64_0
C:\Boost\boost_1_64_0/lib64-msvc-14.1
C:/Boost/boost_1_64_0
CMake Error at C:/Program
Files/CMake/share/cmake-3.8/Modules/FindBoost.cmake:1842 (message):
Unable to find the requested Boost libraries.
Boost version: 1.64.0
Boost include path: C:/Boost/boost_1_64_0
Could not find the following Boost libraries:
boost_system
boost_filesystem
boost_program_options
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR
to the directory containing Boost libraries or BOOST_ROOT to the
location of Boost. Call Stack (most recent call first):
CMakeLists.txt:78 (find_package)
CMake Error at CMakeLists.txt:84 (message): Boost not found
Could someone help please? I have spent hours on this but couldn't figure out why this doesn't work.
First of all, what CMake version do you use? Recently a regression fix was included into 3.8.1 release -- it was about backslashes in BOOST_ROOT.
Secondly, you don't need to specify anything else ('cept maybe the BOOST_ROOT) if you are using official prebuilt Windows binaries -- FindBoost.cmake would try to find them as well. (Unfortunately I can't recall since what version.)
Never do set(BOOST_ROOT...) in your CMakeLists.txt -- just pass this parameter to cmake run via -D option. A better way is the following:
if(NOT DEFINED BOOST_ROOT AND NOT "${ENV{BOOST_ROOT}" STREQUAL "")
set(BOOST_ROOT "$ENV{BOOST_ROOT}")
endif()
Use imported targets to link w/ needed Boost libraries and to modify compile/linker flags per taget. Please avoid to modify "global" compiler/linker options -- i.e. use corresponding target_xxx commands instead of add_definitions & etc.
I use the following script to load boost with CMake (working with Linux and Windows) :
set(BoostPath "${DefaultBoostPath}" CACHE PATH "Path to Boost")
message(STATUS "Path to Boost: ${BoostPath}")
set(BOOST_ROOT "${BoostPath}")
set(Boost_USE_MULTITHREAD ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_NO_SYSTEM_PATHS ON)
set(Boost_ADDITIONAL_VERSIONS "1.57.0" "1.57" "1.58.0" "1.58" "1.59.0" "1.59" "1.60.0" "1.60" "1.61.0" "1.61" "1.62.0" "1.62" "1.63.0" "1.63" "1.64.0" "1.64")
find_package(Boost ${RequiredBoostVersion} REQUIRED COMPONENTS ${RequiredBoostComponents})
mark_as_advanced(FORCE Boost_DIR)
set(BoostVersion "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
message(STATUS "Boost version: ${BoostVersion}")
if(CompilerName STREQUAL "gcc")
set(System_LIBRARIES ${System_LIBRARIES} pthread rt)
endif()
You can see I have to add some versions of Boost because my version of CMake doesn't know last versions.
What's your CMake version ? Maybe it's the same problem.
Where are your headers? I don't think it found the include directory (which is necessary for this to be successful).
Search for FindBoost.cmake in your cmake installation directory, there are lots of useful things in there for troubleshooting.
using set(Boost_DEBUG ON) can help you figure out which paths are searched and what the filenames of the libraries are searched. You can specify the include directory (directory where folder boost is stored) with set(Boost_INCLUDEDIRS ${BOOST_ROOT}/inc), though what I just showed is one of the places that FindBoost.cmake searches.
Also, you don't need set(BOOST_ROOT "$ENV{BOOST_ROOT}"). FindBoost.cmake does that for you if you don't set ${BOOST_ROOT}.
Note that if you just downloaded boost, extracted the archive to ${BOOST_ROOT} and compiled with b2, then all of your files are in ${BOOST_ROOT}/stage. This is also a good place for them to reside. If you manually copy files somewhere else, then FindBoost may have some troubles finding them.

How to use CMake RPath for boost.Python

I'm writing a Python extension module in C++ using Boost.Python. However, I
would like to use a newer version of the Boost library than the system
installation offers. This newer version of boost is contained in
BOOST_ROOT=$HOME/opt/boost/1.55.0.
Following this guide on how
to use RPath in CMake I came up with the following CMakeLists.txt.
cmake_minimum_required(VERSION 2.8)
project("test")
set(PROJECT_DESC "Test Boost.Python")
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
add_definitions(-std=c++11 -Wall -Wextra -pedantic)
find_package(PythonInterp REQUIRED)
find_package(PythonLibsNew REQUIRED)
find_package(Boost COMPONENTS python REQUIRED)
message(STATUS "Using Boost installation in:")
message(STATUS " INCLUDE: ${Boost_INCLUDE_DIRS}")
message(STATUS " LIB: ${Boost_LIBRARIES}")
include_directories(
${PROJECT_SOURCE_DIR}
${PYTHON_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
macro(add_python_module _name _srccpp)
PYTHON_ADD_MODULE(${_name} ${_srccpp})
target_link_libraries(${_name} ${Boost_LIBRARIES})
endmacro()
add_python_module(ownership ownership.cpp)
Then I run the following commands to build the module
mkdir build; cd build
cmake -DCMAKE_INSTALL_PATH="$BOOST_ROOT/lib" ..
make
The status message after running cmake points to the right boost
installation. (The CMake boost module picks up the environment variable
$BOOST_ROOT) I.e. the CMake variable Boost_LIBARIES points to
$BOOST_ROOT/lib/libboost_python.so.
But, if I check which libraries would actually be used, the system libraries
are listed:
$ ldd ownership.so
# ...
libboost_python.so.1.53.0 => /usr/lib64/libboost_python.so.1.53.0 (0x00007f09abfc1000)
# ...
This is version 1.53, even though the status message above explicitely pointed
to 1.55.
What am I doing wrong? How can I get ldd to pick the library in
$BOOST_ROOT/lib/libboost_python.so.1.55.0?
First of all as I already mentioned in commens you don't need to use CMake RPATH-manipulations
options. Example: http://pastebin.com/UDyYbQ1d, output: standard and custom
Do you know of a way of convincing CMake otherwise even if LIBRARY_PATH is set
This issue is not related to CMake, it's compiler responsibility. Read this discussion.
Solution
You can clear LIBRARY_PATH if you set BOOST_ROOT variable explicitly. And you can check
environment variable in CMakeLists.txt to avoid this problem in future:
string(COMPARE NOTEQUAL "$ENV{LIBRARY_PATH}" "" library_path_warning)
if(library_path_warning)
message(
WARNING
"LIBRARY_PATH environment variable is not empty ($ENV{LIBRARY_PATH}) "
"This may cause dynamic linking errors!"
)
endif()

XCode #include bug - not found in header file but in cxx

I created a XCode project with CMake including the Boost 1.55 library and I got into a problem I can't solve by myself.
The include
#include "boost/filesystem.hpp"
just works in EIATHelper.cxx, but not in header EIATHelper.h. In the header it says "file not found" and consequently the build fails. But still the include seems to work, because Xcode doesn't bitch about the used objects defined in "the missing" filesystem.hpp.
Important! When I put the include and all my code into the .cxx files everything works (build/execute).
I added a screenshot who may helps to understand the problem better. (of course I didn't use the double #include):
The project is completely created with CMake.
CMakeLists.txt from subfolder header:
project(${PROJECT_NAME})
add_library(helper
${PROJECT_NAME}Helper.h
${PROJECT_NAME}Helper.cxx
)
set(BOOST_ROOT /Users/name/Libs/Boost/bin)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_DEBUG ON)
set(BOOST_INCLUDEDIR /Users/name/Libs/Boost/bin/include)
set(BOOST_LIBRARYDIR /Users/name/Libs/Boost/bin/lib)
find_package(Boost COMPONENTS
system
filesystem
log
log_setup
)
include_directories(${Boost_INCLUDE_DIRS})
if(NOT Boost_FOUND)
message("Boost was NOT found")
endif()
target_link_libraries(helper ${BOOST_LIBRARIES})
Edit: I created a Eclipse CDT4 Project with CMake, same problem here. Header filsystem.hpp not found in the EIATHelper.h. So I guess something has to be wrong with my project settings, regardless of the IDE.
just works in EIATHelper.cxx, but not in header EIATHelper.h
No, it's not. EIATHelper.cxx includes EIATHelper.h, so "header not found" error appears
first in EIATHelper.h and is kind of a fatal error - compilation stops without processing EIATHelper.cxx (hence without reporting any errors in EIATHelper.cxx).
I'm pretty sure that error is in finding boost libraries. Some notes:
BOOST_INCLUDEDIR and BOOST_LIBRARYDIR is a hints. If you set BOOST_ROOT and libraries is in a standard paths (lib and include) you don't need them.
Boost is mandatory for EIATHelper.{h,cxx} it's better to use REQUIRED suboption
(you don't need to check Boost_FOUND):
find_package(Boost REQUIRED system filesystem log log_setup)
CMake variables is case-sensitive, use Boost_LIBRARIES instead of BOOST_LIBRARIES
Do not hardcode BOOST_ROOT variable, it's not user friendly. At least do something like that:
if(NOT BOOST_ROOT)
set(BOOST_ROOT /some/default/path/to/boost)
endif()

cmake find sqlite3 library on windows

I am having more trouble than I'd expect getting CMake to find the sqlite3.dll library on Windows 7 (64-bit if that matters). I have downloaded and placed the latest sqlite3.dll and sqlite3.def files to C:\Windows\System32. I am using the FindSqlite3.cmake module below:
IF( SQLITE3_INCLUDE_DIR AND SQLITE3_LIBRARY_RELEASE AND SQLITE3_LIBRARY_DEBUG )
SET(SQLITE3_FIND_QUIETLY TRUE)
ENDIF( SQLITE3_INCLUDE_DIR AND SQLITE3_LIBRARY_RELEASE AND SQLITE3_LIBRARY_DEBUG )
FIND_PATH( SQLITE3_INCLUDE_DIR sqlite3.h )
FIND_LIBRARY(SQLITE3_LIBRARY_RELEASE NAMES sqlite3 )
FIND_LIBRARY(SQLITE3_LIBRARY_DEBUG NAMES sqlite3 sqlite3d HINTS /usr/lib/debug/usr/lib/ C:/Windows/System32/ )
IF( SQLITE3_LIBRARY_RELEASE OR SQLITE3_LIBRARY_DEBUG AND SQLITE3_INCLUDE_DIR )
SET( SQLITE3_FOUND TRUE )
ENDIF( SQLITE3_LIBRARY_RELEASE OR SQLITE3_LIBRARY_DEBUG AND SQLITE3_INCLUDE_DIR )
IF( SQLITE3_LIBRARY_DEBUG AND SQLITE3_LIBRARY_RELEASE )
# if the generator supports configuration types then set
# optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
IF( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE )
SET( SQLITE3_LIBRARIES optimized ${SQLITE3_LIBRARY_RELEASE} debug ${SQLITE3_LIBRARY_DEBUG} )
ELSE( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE )
# if there are no configuration types and CMAKE_BUILD_TYPE has no value
# then just use the release libraries
SET( SQLITE3_LIBRARIES ${SQLITE3_LIBRARY_RELEASE} )
ENDIF( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE )
ELSEIF( SQLITE3_LIBRARY_RELEASE )
SET( SQLITE3_LIBRARIES ${SQLITE3_LIBRARY_RELEASE} )
ELSE( SQLITE3_LIBRARY_DEBUG AND SQLITE3_LIBRARY_RELEASE )
SET( SQLITE3_LIBRARIES ${SQLITE3_LIBRARY_DEBUG} )
ENDIF( SQLITE3_LIBRARY_DEBUG AND SQLITE3_LIBRARY_RELEASE )
IF( SQLITE3_FOUND )
IF( NOT SQLITE3_FIND_QUIETLY )
MESSAGE( STATUS "Found Sqlite3 header file in ${SQLITE3_INCLUDE_DIR}")
MESSAGE( STATUS "Found Sqlite3 libraries: ${SQLITE3_LIBRARIES}")
ENDIF( NOT SQLITE3_FIND_QUIETLY )
ELSE(SQLITE3_FOUND)
IF( SQLITE3_FIND_REQUIRED)
MESSAGE( FATAL_ERROR "Could not find Sqlite3" )
ELSE( SQLITE3_FIND_REQUIRED)
MESSAGE( STATUS "Optional package Sqlite3 was not found" )
ENDIF( SQLITE3_FIND_REQUIRED)
ENDIF(SQLITE3_FOUND)
This works fine on Linux, but not on Windows. I have spent a few hours now attempting small changes to other CMAKE variables with no luck. It seems like it should be straight forward getting CMake to find this dll. Could I get some help getting this to find the sqlite3 library on Windows?
There are some issues here and also some weird Windows stuff!
First issue; when searching for a library on Windows with MSVC as the generator, CMake will always look for a ".lib" file - never a ".dll", even if you specify e.g. sqlite3.dll as the NAMES argument to find_library. This is unfortunately not properly documented, in fact the docs for CMAKE_FIND_LIBRARY_SUFFIXES wrongly state:
This specifies what suffixes to add to library names when the find_library command looks for libraries. On Windows systems this is typically .lib and .dll, meaning that when trying to find the foo library it will look for foo.dll etc.
You can easily check this; simply add
message("CMAKE_FIND_LIBRARY_SUFFIXES: ${CMAKE_FIND_LIBRARY_SUFFIXES}")
to your CMakeLists.txt. You should see output like:
CMAKE_FIND_LIBRARY_SUFFIXES: .lib
This thread from the CMake mailing list further confirms this behaviour. If you really need to find the dlls, you'll need to use the find_file command, e.g:
find_file(SQLITE3_DLL_DEBUG NAMES sqlite3d.dll PATHS ...)
The next issue is a minor one. You should prefer PATHS to HINTS as the argument in find_xxx commands if it's a hard-coded guess. From the docs for find_library:
3. Search the paths specified by the HINTS option. These should be paths computed by system introspection, such as a hint provided by the location of another item already found. Hard-coded guesses should be specified with the PATHS option.
A slightly more serious issue is in the line:
FIND_LIBRARY(SQLITE3_LIBRARY_DEBUG NAMES sqlite3 sqlite3d ...)
You should specify sqlite3d first then sqlite3 or sqlite3 will incorrectly be chosen as the Debug library if both are available.
And now the weirdness...
On a Windows x64 system, the find_xxx partially ignores the C:\Windows\System32 directory in favour of the C:\Windows\SysWOW64 one.
If you don't have the sqlite3.lib in C:\Windows\SysWOW64, then the find_library command will always fail, regardless of the PATHS argument.
However, if you do have C:\Windows\SysWOW64\sqlite3.lib, then any combination of C:/Windows/SysWOW64 and/or C:/Windows/System32 as the PATHS argument finds the library, but sets the full path to C:/Windows/System32/sqlite3.lib even if C:/Windows/System32/sqlite3.lib doesn't exist! This is obviously useless if the library isn't there; a linker error will result.
There is some further reading again from the CMake mailing list here.
Having said that, if you're linking, you'll be using the .lib files, not the .dlls, and System32 & SysWOW64 aren't really the place for .lib files.
I didn't find that cmake looks for .lib. pls.
please check the cmake file and findSqlite.cmake file inside cmake folder and check for paths it is looking for.
when I gave the full path to the "dll", it worked for me corresponding to the input variable mentioned in cmake file, and it might work for you too.
If your problem is not solved, notify me to edit the answer.

CMake and Boost

I've searched and found out that a lot of people have the same problem, but no solution exists.
I'm using CMake to generate Makefiles for MinGW and when compiling I'm getting an error:
CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x5e): undefined reference to `_imp___ZN5boost6thread4joinEv'
CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x71): undefined reference to `_imp___ZN5boost6threadD1Ev'
CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x88): undefined reference to `_imp___ZN5boost6threadD1Ev'
This seems to be a linking problem, I get it. My CMake configuration is:
project(boosttest)
cmake_minimum_required(VERSION 2.6)
include_directories(${boosttest_SOURCE_DIR}/include c:/boost_1_48_0/)
link_directories(c:/boost_1_48_0/lib)
file(GLOB_RECURSE cppFiles src/*.cpp)
add_executable(boosttest ${cppFiles})
target_link_libraries(boosttest libboost_thread-mgw46-mt-1_48.a)
First I tried using find_package(Boost COMPONENTS thread) and it was working the same way, so I thought to try to do this manually and I still get the same error.
Any insights on this?
I've compiled it for mingw using bjam and as a static link. Also tried doing:
add_library(imp_libboost_thread STATIC IMPORTED)
set_property(TARGET imp_libboost_thread PROPERTY IMPORTED_LOCATION c:/boost_1_48_0/lib/libboost_thread-mgw46-mt-1_48.a)
target_link_libraries(boosttest imp_libboost_thread)
And I still get the same error messages.
For mingw32 you may add definition BOOST_THREAD_USE_LIB. And linking with boost::thread will work. Also you may need Threads package (but i'm not sure, may be it needs only for *nix platforms).
Here is part of my CMakeLists. I copied it from project, which uses boost::thread, and compiles under mingw-gcc (and other compilers):
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_ADDITIONAL_VERSIONS "1.44" "1.44.0")
find_package(Boost COMPONENTS thread date_time program_options filesystem system REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
find_package(Threads REQUIRED)
#...
if (WIN32 AND __COMPILER_GNU)
# mingw-gcc fails to link boost::thread
add_definitions(-DBOOST_THREAD_USE_LIB)
endif (WIN32 AND __COMPILER_GNU)
#...
target_link_libraries(my_exe
${CMAKE_THREAD_LIBS_INIT}
#...
${Boost_LIBRARIES}
)
In my opinion, this question is similar to this question and this one. My best guess would be that you need the same resolution as in my answer to the first question.
I would strongly recommend the use of find_package (Boost ) and take care with the auto-linking:
project(boosttest)
cmake_minimum_required(VERSION 2.6)
# Play with the following defines
# Disable auto-linking.
add_definition( -DBOOST_ALL_NO_LIB )
# In case of a Shared Boost install (dlls), you should then enable this
# add_definitions( -DBOOST_ALL_DYN_LINK )
# Explicitly tell find-package to search for Static Boost libs (if needed)
set( Boost_USE_STATIC_LIBS ON )
find_package( Boost REQUIRED COMPONENTS thread )
include_directories( ${Boost_INCLUDE_DIRS} )
file(GLOB_RECURSE cppFiles src/*.cpp)
add_executable(boosttest ${cppFiles})
target_link_libraries(boosttest ${Boost_LIBRARIES} )

Resources