0
votes

I am trying to compile c++ software depending on boost with CMake. With the same source code and CMakeLists.txt files, I succeeded with my own laptop (ubuntu 11 with boost1.42), but I am getting the following error message with my workstation (RHEL6.2 with boost 1.41) in research group (btw, boost1.41 should be enough):

main/main.cpp: In function ‘path
make_path(const std::string&)’:
main/main.cpp:50: error: invalid
conversion from ‘bool (*)(const std::string&)’ to ‘void*’
main/main.cpp:50: error:
initializing argument 2 of ‘boost::filesystem3::path::path(const Source&,
typename
boost::enable_if<boost::filesystem3::path_traits::is_pathable<typename
boost::decay<Source>::type>, void>::type*) [with Source =
std::basic_string<char, std::char_traits<char>, std::allocator<char> >]’
main/main.cpp: In function ‘int
main(int, char**)’:
main/main.cpp:664: error: ‘class
path’ has no member named ‘native_file_string’
main/main.cpp:676: error: ‘class
path’ has no member named ‘native_file_string’
make[2]: *** [main/CMakeFiles/vina_main.dir/main.cpp.o] Error 1
make[1]: *** [main/CMakeFiles/vina_main.dir/all] Error 2
make: *** [all] Error 2

I don't quite understand the error message and don't know how to fix it. Can anyone help me?

======================= update =========================

The above error message is fixed thanks to your help, but I still get the error message indicating linking failure between my executable file and boost libraries. I did link it within CMakeLists.txt by 'target_link_libraries (vvv_main vvv ${Boost_LIBRARIES})'. The error message is like:

CMakeFiles/vvv_main.dir/main.cpp.o: In function              '__static_initialization_and_destruction_0':
/usr/local/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'

.......

I read other related posts here, but still have no clue how to fix my problem. Thanks!

1
Can you show us line 50 of main.cpp? And perhaps some context around that line? - wilhelmtell
Also, in line 664 you seem to be calling a none-existent method. I know that boost::filesystem v3 breaks many things of v2, so check the functions that were removed. - wilhelmtell
In line 50 of main.cpp you're instantiating a boost::fileystem3::path object. What is the second parameter you're passing to the constructor? - wilhelmtell
Are you sure this is version 1.41? Because v3 is only meant to be the default from Boost 1.46 onwards. The other thing is that path::native_file_string is deprecated and (I think) has been for a while. Whether Boost actually provides deprecated bits or not is controlled by a #define; maybe it's defined differently on your two systems. - Gareth McCaughan
@wilhelmtell Thank you. The line 50 is :' return path(str, boost::filesystem::native); '. The problem is due to default Boost filesystem version. But now I have some problem for linking executable file with boost library. - Tao

1 Answers

1
votes

I would suggest, that you use the find_package routines of CMake together with the required flag and explicitly specifying the components you need. Then there is no need to manually set the libraries.

For your project

FIND_PACKAGE(Boost 1.41 COMPONENTS filesystem system REQUIRED)
MESSAGE(STATUS "** Boost Include: ${Boost_INCLUDE_DIR}")
MESSAGE(STATUS "** Boost Libraries: ${Boost_LIBRARIES}")

together with

TARGET_LINK_LIBRARIES(your_project ${Boost_LIBRARIES})

should do the trick. Specifying the version (here 1.41) makes CMake if only an older version of boost is available. Specifying the components (components = boost libraries that are not header-only) makes CMake complain if those are not available and also automatically adds those to the variable Boost_LIBRARIES. The Message statements are not necessary but I like to have some feedback...

In case you would like to manually download and install the newest version of boost (which I normally do since Linux distributions tend to be somewhat slow with respect to boost packaging) alongside the version provided by the system, then you can hint the find_package scripts for boost to the custom location via

SET(BOOST_ROOT "$ENV{HOME}/usr") 

which of course goes before the find_package call (in this example boost would have been installed into the prefix $HOME/usr).

One last remark - I sometimes used to have problems with older versions of the FindBoost.cmake script (especially those from the old CMake 2.6) that does all the magic when find_package(Boost) is called. It should not be a problem for Boost 1.41, but in case there are problems finding (newer versions of) Boost even though you're absolutely sure it is correctly installed, you might want to try a more recent version of FindBoost.cmake. For example from the gitweb, it should be in the Modules tree.