can't link boost thread/any boost with cmake

Get answers to all your basic programming questions. No Ogre questions, please!
themean
Greenskin
Posts: 104
Joined: Wed Feb 29, 2012 11:50 am
x 1

can't link boost thread/any boost with cmake

Post by themean »

I'm porting my engine from qmake to cmake.I'm allready done but can't link boost tread required from ogre.
My cmake code is.

Code: Select all

// Top level cmake
if(Boost_FOUND)
set(IncludeDirectories ${IncludeDirectories} ${Boost_INCLUDE_DIR})
set(BOOST_LIB ${Boost_LIBRARIES})
endif(Boost_FOUND)

//exe cmake
add_executable(${GameName} ${Sources})
set(LinkLibs ${LinkLibs} ${OGRE_LIB} ${BOOST_LIB})
target_link_libraries(${GameName} ${LinkLibs})
My issue from linker is :
:-1: error: LNK1104: cannot open file 'libboost_thread-vc100-mt-gd-1_47.lib'
May be I must set some library paths i don't know

OS win 7, Compiler msvc 2010 cl, IDE Qt creator,Boost library 1.47 from boost installer
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: can't link boost thread/any boost with cmake

Post by jacmoe »

<edit>
Here is how we do this for Ogitor:

Code: Select all

# Find Boost
# Prefer static linking in all cases
if (NOT OGRE_BUILD_PLATFORM_IPHONE)
    if (WIN32 OR APPLE)
        set(Boost_USE_STATIC_LIBS TRUE)
    else ()
        # Statically linking boost to a dynamic Ogre build doesn't work on Linux 64bit
        set(Boost_USE_STATIC_LIBS ${OGRE_STATIC})
    endif ()
    set(Boost_ADDITIONAL_VERSIONS "1.38.0" "1.38" "1.39.0" "1.39" "1.40.0" "1.40" "1.44.0" "1.44" "1.45" "1.46" "1.47" "1.48" "1.49" "1.49.0" "1.50" "1.50.0")
    # Components that need linking (NB does not include header-only components like bind)
    set(OGRE_BOOST_COMPONENTS thread date_time regex)
    find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
    if (NOT Boost_FOUND)
        # Try again with the other type of libs
        set(Boost_USE_STATIC_LIBS NOT ${Boost_USE_STATIC_LIBS})
        find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
    endif()
    if (Boost_FOUND AND WIN32)
        if(Boost_VERSION GREATER 104700)
            set(OGRE_BOOST_COMPONENTS thread date_time regex system)
        endif(Boost_VERSION GREATER 104700)
        if(Boost_VERSION GREATER 104900)
            set(OGRE_BOOST_COMPONENTS thread date_time regex system chrono)
        endif(Boost_VERSION GREATER 104900)
        find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
    endif(Boost_FOUND AND WIN32)
    find_package(Boost QUIET)
endif(NOT OGRE_BUILD_PLATFORM_IPHONE)
Then, later:

Code: Select all

include_directories(${Boost_INCLUDE_DIR})
And:

Code: Select all

target_link_libraries(Ogitor ${OGRE_LIBRARY} ${OGRE_Terrain_LIBRARY} ${OGRE_Paging_LIBRARY} PagedGeometry OFS ${Boost_LIBRARIES})
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: can't link boost thread/any boost with cmake

Post by jacmoe »

My guess is that BOOST_Found is false in your script.
Actually, I think I'm 98% sure it's not since the find boost script is not run for your script.
It's all about scope.
So run it again, like we do for Ogitor (see above).
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
CABAListic
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 2903
Joined: Thu Jan 18, 2007 2:48 pm
x 58

Re: can't link boost thread/any boost with cmake

Post by CABAListic »

For MSVC you must also disable the automatic linking from Boost headers, or you may run into trouble. The error message you posted actually indicates this may be the problem.

There's a preprocessor define for this purpose, I forgot its name, though.
themean
Greenskin
Posts: 104
Joined: Wed Feb 29, 2012 11:50 am
x 1

Re: can't link boost thread/any boost with cmake

Post by themean »

10x a lot :)