0

I am new to C/C++, Cmake, and Boost; I've read every post in SO of other people having my same problem and I couldn't figure it out.

EDIT: as explained in the comment, I already read another similar post, and I'm already doing what is proposed in the accepted solution (i.e. using COMPONENTS libraryName and set(Boost_USE_STATIC_LIBS OFF). Actually, putting Boost_USE_STATIC_LIBS to OFF removed the "lib" prefix from the libraries name in the argn parameter. And I seem to need that prefix..

I built Boost for Android with bjam and, hoping that I have done everything correctly, I used this command:

./b2 install include=/home/myUser/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include include=/home/myUser/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include include=/home/myUser/android-ndk-r12b/platforms/android-19/arch-arm/usr/include toolset=gcc-arm target-os=android --prefix=/home/myUser/boost_build --with-system --with-random --with-date_time -sNO_BZIP2=1 link=static runtime-link=shared threading=multi

And I end up with this folder structure:

/home/myUser/boost_build/
    - include/
        -boost/
            - # a lot of folders and .hpp files
    - lib/
        - libboost_date_time.a
        - libboost_random.a
        - libboost_system.a

Then I launch Cmake in order to compile my project with this command:

cmake -DBOOST_ROOT=/home/myUser/boost_build -DBOOST_INCLUDEDIR=/home/myUser/boost_build/include -DBOOST_LIBRARYDIR=/home/myUser/boost_build/lib -DBOOST_VER:STRING=1.61.0 ./

And this is the revelant part of CMakeList.txt:

option(BUILD_SHARED_LIBS "Build the shared library" OFF)
#option(Boost_USE_STATIC_LIBS "Use Boost static version" ON)
set(Boost_USE_STATIC_LIBS ON)
#tried both of the versions above, I don't even know the difference

set(BOOST_VER "1.61.0")
set(Boost_VERSION 106100)

set(Boost_USE_MULTITHREADED ON) 
set(Boost_USE_STATIC_RUNTIME OFF) 
set(Boost_FIND_QUIETLY 0 )
set(Boost_DEBUG 1)

find_package(Boost ${BOOST_VER} REQUIRED COMPONENTS system date_time random) 

Finally, I end up with this error:

-- [ /usr/share/cmake-3.5/Modules/FindBoost.cmake:1558 ] Boost_FOUND = 1
# e.d.: Notice that Boost_FOUND = 1. Reading through the FindBoost code, I understand that this means that he found the include directory with the header files.
CMake Error at /usr/share/cmake-3.5/Modules/FindBoost.cmake:1719 (message):
  # e.d.: don't mind the line numbers in the FindBoost.cmake files... I added a lot of messages around, to debug

  Unable to find the requested Boost libraries.

  Boost version: 1.61.0

  Boost include path: /home/myUser/boost_build/include

  Could not find the following static Boost libraries:

          boost_system
          boost_date_time
          boost_random

  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:48 (find_package)

If I try to print the find_library parameters, in FindBoost.cmake:

message(STATUS "looking for library: var: ${var} , dollarvar: ${${var}}, argn: ${ARGN}")
find_library(${var} ${ARGN})
message(STATUS "dollarvar: ${${var}}" )

I get:

-- looking for library: var: Boost_SYSTEM_LIBRARY_RELEASE , dollarvar: , argn: NAMES;libboost_system-ghs-mt-1_61;libboost_system-ghs-mt;libboost_system-mt-1_61;libboost_system-mt;libboost_system;HINTS;/home/myUser/boost_build/lib;/home/myUser/boost_build/lib;/home/myUser/boost_build/stage/lib;/home/myUser/boost_build/include/lib;/home/myUser/boost_build/include/../lib;/home/myUser/boost_build/include/../lib/;/home/myUser/boost_build/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib;NAMES_PER_DIR;DOC;Boost system library (release)
-- dollarvar: Boost_SYSTEM_LIBRARY_RELEASE-NOTFOUND

EDIT2: I tried to copypaste my boost_build directory and my project directory from Linux to Windows, where I installed CMake too, and with my great annoyance... cmake under windows worked. Unfortunately cmake under windows generates some Visual Studio Project files, instead of a makefile. Now I'm wondering why cmake version 3.5.1 under Ubuntu 16.04 doesn't work, and cmake version 3.6.2 under Windows 7 does.

Community
  • 1
  • 1
ocramot
  • 1,361
  • 28
  • 55
  • 2
    Possible duplicate of [CMake: undefined reference to boost library](http://stackoverflow.com/questions/39513269/cmake-undefined-reference-to-boost-library) – rocambille Sep 22 '16 at 15:30
  • @wasthishelpful I don't think it is :( I already read that post, and I'm already doing what is proposed in the accepted solution (i.e. using `COMPONENTS libraryName` and `set(Boost_USE_STATIC_LIBS OFF)`. Actually, putting Boost_USE_STATIC_LIBS to OFF removed the "lib" prefix from the libraries name in the argn parameter. And I seem to need that prefix... – ocramot Sep 22 '16 at 15:37
  • So your problem is not in the library's prefix, but is in the library's **suffix**, isn't it? Suffix `-mt` means *multithreading*, suffux `-ghs` corresponds to "GHSMULTI", whatever it means. See module [FindBoost.cmake](https://github.com/Kitware/CMake/blob/master/Modules/FindBoost.cmake) about origin of different components for libraries names. – Tsyvarev Sep 22 '16 at 17:15
  • @Tsyvarev I'm really newbie in CMake, but I think to understand that `find_library` is looking for EVERY combination in the `NAMES` list... and it will return `FOUND` if at least one of them matches (...am I right? Really, I don't know). Therefore, it should work with the last element of the list, that has no suffix. – ocramot Sep 22 '16 at 17:52
  • Hm, you are right, correct name is also exists in the search list. Probably, something wrong with prefix or extension which is search by `find_library()`. BTW, you may try to call `find_library()` by yourself, and see whether it finds something or not. – Tsyvarev Sep 22 '16 at 19:13

0 Answers0