1
votes

I try to set up my cross-platform development environment with CMake.

I encounter the following error only when I try to compile with poky toolchain:

make[2]: * No rule to make '/opt/poky/1.3/sysroots/armv5te-poky-linux-gnueabi/usr/lib/libboost_thread.so', needed by 'test'. Stop

I tried to set up the CMake toolchain in two different methods and the result is the same.

Method1 (simple):

###################################################################################
# Cross compile using Poky prebuilt toolchains, you need to source the
# environment first:
#
# $ rm -fr build; mkdir build; cd build
# $ source /opt/poky/1.3/environment-setup-armv5te-poky-linux-gnueabi
# $ cmake -DCMAKE_TOOLCHAIN_FILE=Toolchains/arm-poky-linux-gnueabi-simple.cmake
# $ make
###################################################################################

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)

SET(CMAKE_FIND_ROOT_PATH $ENV{OECORE_TARGET_SYSROOT})
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Method2:

# this one is important
SET( CMAKE_SYSTEM_NAME Linux )

# this one not so much
SET( CMAKE_SYSTEM_VERSION 1 )

# specify the cross compiler
SET( CROSS_COMPILER_PATH /opt/poky/1.3/sysroots/x86_64-pokysdk-linux/usr/bin/armv5te-poky-linux-gnueabi )
SET( C_CROSS_COMPILER arm-poky-linux-gnueabi- )

FIND_PROGRAM( CCACHE ccache )
IF( CCACHE )
    SET( CMAKE_C_COMPILER "${CCACHE}" "${CROSS_COMPILER_PATH}/${C_CROSS_COMPILER}gcc" )
    SET( CMAKE_CXX_COMPILER "${CCACHE}" "${CROSS_COMPILER_PATH}/${C_CROSS_COMPILER}g++" )
ELSE( CCACHE )
    SET( CMAKE_C_COMPILER "${CROSS_COMPILER_PATH}/${C_CROSS_COMPILER}gcc" "" )
    SET( CMAKE_CXX_COMPILER "${CROSS_COMPILER_PATH}/${C_CROSS_COMPILER}g++" "" )
ENDIF(CCACHE)

SET( CMAKE_RANLIB "${CROSS_COMPILER_PATH}/${C_CROSS_COMPILER}ranlib" )
SET( CMAKE_AR "${CROSS_COMPILER_PATH}/${C_CROSS_COMPILER}ar" )

SET( CMAKE_COMPILER_IS_GNUCC 1 )
SET( CMAKE_COMPILER_IS_GNUCXX 1 )

INCLUDE_DIRECTORIES( BEFORE SYSTEM /opt/poky/1.3/sysroots/armv5te-poky-linux-gnueabi/usr/include )
LINK_DIRECTORIES( /opt/poky/1.3/sysroots/armv5te-poky-linux-gnueabi/usr/lib )

# where is the target environment 
SET( CMAKE_FIND_ROOT_PATH /opt/poky/1.3/sysroots/armv5te-poky-linux-gnueabi/ )

#search for libraries and header files only in the target environment
SET( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
SET( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )

# search for programs in the build host directories
SET( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )

My CMake project is:

cmake_minimum_required( VERSION 2.8.9 )

project ( TEST ) 

set( BOOST_COMPONENTS thread )

find_package( Boost COMPONENTS ${BOOST_COMPONENTS} )

add_executable( test test.cpp ) 
target_link_libraries( test ${Boost_THREAD_LIBRARY} )

My cpp code used for tests:

#include <boost/thread/thread.hpp>
#include <iostream>

void hello()
{
    std::cout << "Hello!" << std::endl;
}

int main()
{
    boost::thread thrd( &hello );
    thrd.join();
    return 0;
}

Thank you by advance for your help

2
Did you build your Boost.Thread library first ?Piotr Skotnicki
Yes of course. I can even compile with a standard MakefileSylvain Pastor
maybe: link_directories(${Boost_LIBRARY_DIR}) and remove set( Boost_REALPATH on ) ?Piotr Skotnicki
It was just a test, Without the problem is the same.Sylvain Pastor
but you set link directories only to /opt/poky/1.3/sysroots..., how about ${Boost_LIBRARY_DIR} ?Piotr Skotnicki

2 Answers

0
votes

The solution to my problem:

Solution1:

###################################################################################
#
# Cross compile using Poky prebuilt toolchains, you need to source the
# environment first:
#
# $ rm -fr build; mkdir build; cd build
# $ source /opt/poky/1.3/environment-setup-armv5te-poky-linux-gnueabi
# $ cmake -DCMAKE_TOOLCHAIN_FILE=Toolchains/arm-poky-linux-gnueabi-simple.cmake
# $ make
#
###################################################################################

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)

SET(CMAKE_FIND_ROOT_PATH /home/sylvain/Share/dev/Dev2M_CMakeCrossCompile/temp/boost $ENV{OECORE_TARGET_SYSROOT})
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

My CMake project:

cmake_minimum_required( VERSION 2.8.9 )

project ( TEST ) 

set( BOOST_COMPONENTS atomic system thread )

#Very useful to find the source of the problem
#set( Boost_DEBUG on )

#Set the version of gcc in my case that is the source of my problems otherwise the module defines the gcc version of my ubuntu PC
set( Boost_COMPILER "-gcc" )

set( BOOST_ROOT /home/sylvain/Share/dev/Dev2M_CMakeCrossCompile/temp/boost )

find_package( Boost COMPONENTS ${BOOST_COMPONENTS} true )

set( MY_BOOST_LIBRARIES
    ${Boost_ATOMIC_LIBRARY}
    ${Boost_SYSTEM_LIBRARY}
    ${Boost_THREAD_LIBRARY}
)

add_executable( test test.cpp ) 
target_link_libraries( test ${MY_BOOST_LIBRARIES} )
0
votes

Boost is usually linked as follows:

FIND_PACKAGE( Boost COMPONENTS ${TheLibs} REQUIRED )    
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})

add_executable(test test.cpp)
target_link_libraries( test ${Boost_LIBRARIES} )

For clarification: The message "no rule to make" often means that the target file doesn't exist. Most of the times i check the file manually. If the file exists and you still get errors you can try to link manually by setting linker flags e.g.:

SET(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -l${PATH_TO_LIBRARY}")

If it still doesn't work, then call make with the Verbose flag (usually VERBOSE=1) and look if the link step is executed correctly.


A general approach to link a external library is to add it as an own target. The advantage is that you can reuse it for multiple executables or libraries in the same Project. You wouldn't use that for boost, because they usually handle that for you.

add_library( libABCDEFG SHARED/STATIC IMPORTED )
set_target_properties( mylib PROPERTIES IMPORTED_LOCATION ${PathToLibrary} )
TARGET_LINK_LIBRARIES(test libABCDEFG)

Another hint to CMake usage with Toolchains:

A Toolchain is only included on the first creation of the project (except you include it otherwise). If you change any settings inside of the toolchain you have to delete the CMake Cache and re-execute the first CMake call.