building boost locale library on Windows - boost

I am trying to build the boost::locale library (http://cppcms.sourceforge.net/boost_locale/html/tutorial.html#a5771bce93e200c36f7cd9dfd0e5deaa) which is still in review for integration into boost but the cmake command throws up the following:
D:\lib\boost_locale_v2.92\build>cmake ..
-- Looking for ICU libraries
-- Looking for iconv
-- Looking for Boost
CMake Error: The following variables are used in this project, but they are se
to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake fi
s:
BOOST_THREAD
linked by target "boost_locale-static" in directory D:/lib/boost_locale_v2
2
ICU_DATA
linked by target "boost_locale-static" in directory D:/lib/boost_locale_v2
2
ICU_I18N
linked by target "boost_locale-static" in directory D:/lib/boost_locale_v2
2
ICU_INCLUDE_DIR
used as include directory in directory D:/lib/boost_locale_v2.92
ICU_UC
linked by target "boost_locale-static" in directory D:/lib/boost_locale_v2
2
-- Configuring incomplete, errors occurred!
I have got ICU and boost but can't figure out how to modify the out-of-box cmake script for boost::locale. Any help is appreciated

Actually these error messages are clear enough. You need to point where is what: boost thread library location, ICU include directory, and others.

Read the installation instructions carefully:
http://cppcms.sourceforge.net/boost_locale/html/building_boost_locale.html
You need to provide:
cmake -DCMAKE_INCLUDE_PATH=/path/to/boost/include;path/to/icu/include -DCMAKE_LIBRARY_PATH=/path/to/icu/lib ..

Related

Setting up CMake with gfortran in Windows to run CACTUS

My ultimate goal is to run CACTUS. It requires CMake, so I have downloaded both. I think CMake needs a compiler, so I downloaded MinGW (or gfortran or GNU, I'm not really sure the distinction).
Using the MinGW Installation Manager, I've installed mingw32-base, mingw32-gcc-fortran, and also all the MinGW libraries because at one point I thought it would help. I have navigated through
control panel>system>advanced system settings>advanced>environment
variables and in user variables I have added the variables CMake and FC with the values C:\ProgramFiles\CMake\bin and C:\MinGW\bin, respectively.
I also edited the path in system variables to include both of those as well as C:\MinGW\mingw32\bin. I've also downloaded and installed Microsoft Visual Studio 2019 because I read somewhere that it was necessary for gfortran to work, though I have not done anything directly with it so far. At this point, I open Windows command prompt (this is all in Windows 10), navigate to the build folder that I have created in the top CACTUS folder and type
cmake ../
It returns this:
-- Could NOT find BLAS (missing: BLAS_LIBRARIES)
-- LAPACK requires BLAS
-- A library with LAPACK API not found. Please specify library location.
-- Could NOT find OpenMP_Fortran (missing: OpenMP_Fortran_FLAGS OpenMP_Fortran_LIB_NAMES)
CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:272 (message):
The package name passed to `find_package_handle_standard_args` (OpenMP)
does not match the name of the calling package (OPENMP). This can lead to
problems in calling code that expects `find_package` result variables
(e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.17/Modules/FindOpenMP.cmake:579 (find_package_handle_standard_args)
CMakeLists.txt:30 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Could NOT find OpenMP (missing: OpenMP_Fortran_FOUND)
CMake Error at CMakeLists.txt:32 (message):
OPENMP option was set to true (default), but no OpenMP was found. Install
OpenMP, or try again with -DOPENMP=OFF. Exiting.
-- Configuring incomplete, errors occurred!
Starting at the top of that error, I did some googling and found these instructions starting at "Build Instructions to create LAPACK and LAPACKE 3.5.0 dlls for Windows with MinGW". I followed those instructions for Win32. After running C:/MinGW/bin/mingw32-make.exe from command prompt, it gets to 36% and errs with the following message:
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lFALSE
collect2.exe: error: ld returned 1 exit status
SRC\CMakeFiles\lapack.dir\build.make:28574: recipe for target 'bin/liblapack.dll' failed
mingw32-make.exe[2]: *** [bin/liblapack.dll] Error 1
CMakeFiles\Makefile2:2077: recipe for target 'SRC/CMakeFiles/lapack.dir/all' failed
mingw32-make.exe[1]: *** [SRC/CMakeFiles/lapack.dir/all] Error 2
Makefile:181: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2
I have also tried directions here and here and have either had no luck or, frankly, don't understand them. I am not a programmer. I have lived a life spoiled by GUIs and single install programs with everything included. I don't know what to try anymore. I don't really understand what's wrong or, honestly, why I've taken most of the steps I've taken except that someone in another help forum suggested them. I guarantee that I will have follow up questions to your answers, but please help.
EDIT
As requested below, here is the config file for lapack after cmake:
# Load the LAPACK package with which we were built.
set(LAPACK_DIR "C:/Users/x/Downloads/lapack/lapack-3.9.0/build")
find_package(LAPACK NO_MODULE)
# Load lapack targets from the build tree, including lapacke targets.
if(NOT TARGET lapacke)
include("C:/Users/x/Downloads/lapack/lapack-3.9.0/build/lapack-targets.cmake")
endif()
# Hint for project building against lapack
set(LAPACKE_Fortran_COMPILER_ID ${LAPACK_Fortran_COMPILER_ID})
# Report lapacke header search locations from build tree.
set(LAPACKE_INCLUDE_DIRS "C:/Users/x/Downloads/lapack/lapack-3.9.0/build/include")
# Report lapacke libraries.
set(LAPACKE_LIBRARIES lapacke ${LAPACK_LIBRARIES})
And, yes, I did choose to build the LAPACKE Library in CMake.

Boost installation on windows, libraries missing

I am trying to build boost. I followed the instructions here. I create a folder C:\Boost which contains include and libs and I add it to my enviroment path. However, when I tried to build another project with cMake I am getting:
CMake Error at C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:1106 (message):
Unable to find the requested Boost libraries.
Boost version: 1.55.0
Boost include path: C:/Boost/include/boost-1_55
The following Boost libraries could not be found:
boost_system
boost_filesystem
boost_signals
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:88 (find_package)
Any idea about those missing libs?
It's a bad thing to start an answer with a question, but I do it nevertheless:
First, am I right in assuming that you've set an environment variable BOOST_ROOT pointing to C:\Boost? (Simply adding it to the path might not be sufficient here.)
Second, which CMake generator are you running? Visual Studio, Makefile, ninja?
I've head a similar problem recently that was connected to the generator that I was actually using. More precisely, I was trying to create a Ninja project from within cmake-gui and got almost the same error message. However, I was able to create a Visual Studio project in cmake-gui project without problem.
When looking a little closer at the command output for the Ninja case I found the following two lines at the very beginning:
The C compiler identification is unknown
The CXX compiler identification is unknown
This hints at the actual problem. While it is clear which compiler will be in use for Visual Studio (9, 10, 11, ...), cmake cannot infer a default compiler for Ninja because it is a generic build system that runs with different compilers. In the end boost wasn't found because the compiler is unknown.
A simple solution was to open the Developer Command Prompt for the Visual Studio version that you want to run with. When you create the project in this "extended" command prompt CMake will be able to infer the correct compiler. Alternatively, you can set the CMAKE_CXX_COMPILER and CMAKE_C_COMPILER flags when running cmake.
cmake -G "Ninja" <path/to/CMakeLists.txt>
cmake -G "Ninja" <path/to/CMakeLists.txt> -DCMAKE_CXX_COMPILER="path/to/cxx/compiler" -CMAKE_C_COMPILER="path/to/c/compiler"

Boost_DIR-NOTFOUND on CMake

I have been facing some problems when trying to configure a project with CMake.
Even though CMake seems to find the needed libs:
Boost version: 1.49.0
Found the following Boost libraries:
system
thread
chrono
It still can't find its root directory:
Boost_DIR-NOTFOUND
I'm using Linux Mint 15 (Olivia). Thanks in advance.
If you want to check whether the search was successful, you need to check the variable Boost_FOUND instead.
find_package(Boost [...])
if(NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif()
The Boost_DIR variable is only of significance when using Boost's package configuration file (which is currently no longer supported as of Boost 1.54). It is therefore perfectly fine if this value is left in the NOTFOUND state by the find call.
See the documentation for details.

Getting CMake to find flex on Windows

I am trying to use flex on a project and I am trying to use CMake to link flex with my project. I found a FindFLEX.cmake online which I am using for this. You can find it here. This was supposed to be in CMake by default, but I dont think it was. My directory structure is as follows
root
---src
---CMakeLists.txt
---cmake
---Modules
---FindFLEX.cmake
---build
---external
---flex - Where flex is installed
---bin
---flex.exe
---lib
---libfl.a
My src/CMakeLists.txt is as follows
cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
message(${CMAKE_MODULE_PATH})
set( project_name "try_flex" )
message(${project_name})
project(${project_name})
find_package(FLEX)
FLEX_TARGET(Mylexer tokenize.lex ${CMAKE_CURRENT_BINARY_DIR}/tokenize.cpp)
add_executable(${project_name} ${FLEX_Mylexer_OUTPUTS})
target_link_libraries(${project_name} ${FLEX_LIBRARIES})
FLEX_TARGET is supposed to be provided by FindFLEX.cmake when it finds the Flex package. Running the following command in build/ directory didnt find the flex packages
build> cmake ..\src
Then I added the prefix and that worked partially
build> cmake -DCMAKE_PREFIX_PATH=c:\root\external\flex\ ..\src
That found the executable flex.exe , but not the library. The relevant portions of FindFLEX.cmake is shown below
FIND_PROGRAM(FLEX_EXECUTABLE flex DOC "path to the flex executable")
message("DEBUG:"${FLEX_EXECUTABLE})
MARK_AS_ADVANCED(FLEX_EXECUTABLE)
FIND_LIBRARY(FL_LIBRARY NAMES fl DOC "path to the fl library")
message("DEBUG:FL_LIBRARY"${FL_LIBRARY})
MARK_AS_ADVANCED(FL_LIBRARY)
SET(FLEX_LIBRARIES ${FL_LIBRARY})
The message I get on running cmake is
DEBUG:c:/root/external/flex/bin/flex.exe
DEBUG:FL_LIBRARYFL_LIBRARY-NOTFOUND
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake file s:FL_LIBRARY (ADVANCED)
linked by target "try_flex" in directory C:/root/src
-- Configuring incomplete, errors occurred!
Could anyone tell me why I am finding the flex binary but not the library after including the prefix path? Any help would be appreciated.
Thanks
I figured out what the problem is. On Windows, cmake is looking for libfl.lib. But the Windows installation of Flex provides only libfl.a So I needed to add these two lines to my cmake
LIST(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".a")
FIND_LIBRARY(FL_LIBRARY NAMES libfl fl DOC "path to the fl library")
The first line adss .a to list of suffixes searched for libraries, and the second line looks for libfl. That worked

Cmake doesn't find Boost

I'm trying to configure a project using CMake, but it fails to find Boost libraries even though they are in the specified folder. I have specified Boost_INCLUDE_DIR, Boost_LIBRARYDIR and BOOST_ROOT , but I still get an error saying that CMake is not able to find Boost. What could be the reason of such error?
Are you sure you are doing it the correct way? The idea is that CMake sets BOOST_INCLUDE_DIR, BOOST_LIBRARYDIR and BOOST_ROOT automatically. Do something like this in CMakeLists.txt:
FIND_PACKAGE(Boost)
IF (Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ADD_DEFINITIONS( "-DHAS_BOOST" )
ENDIF()
If boost is not installed in a default location and can, thus, not be found by CMake, you can tell CMake where to look for boost like this:
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/win32libs/boost")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/win32libs/boost/lib")
Of course, those two lines have to be before the FIND_PACKAGE(Boost) in CMakeLists.txt.
There is more help available by reading the FindBoost.cmake file itself. It is located in your 'Modules' directory.
A good start is to set(Boost_DEBUG 1) - this will spit out a good deal of information about where boost is looking, what it's looking for, and may help explain why it can't find it.
It can also help you to figure out if it is picking up on your BOOST_ROOT properly.
FindBoost.cmake also sometimes has problems if the exact version of boost is not listed in the Available Versions variables. You can find more about this by reading FindBoost.cmake.
Lastly, FindBoost.cmake has had some bugs in the past. One thing you might try is to take a newer version of FindBoost.cmake out of the latest version of CMake, and stick it into your project folder alongside CMakeLists.txt - then even if you have an old version of boost, it will use the new version of FindBoost.cmake that is in your project's folder.
Good luck.
For me this error was simply because boost wasn't installed so on ubuntu:
sudo apt install build-essential libboost-system-dev libboost-thread-dev libboost-program-options-dev libboost-test-dev
I struggled with this problem for a while myself. It turned out that cmake was looking for Boost library files using Boost's naming convention, in which the library name is a function of the compiler version used to build it. Our Boost libraries were built using GCC 4.9.1, and that compiler version was in fact present on our system; however, GCC 4.4.7 also happened to be installed. As it happens, cmake's FindBoost.cmake script was auto-detecting the GCC 4.4.7 installation instead of the GCC 4.9.1 one, and thus was looking for Boost library files with "gcc44" in the file names, rather than "gcc49".
The simple fix was to force cmake to assume that GCC 4.9 was present, by setting Boost_COMPILER to "-gcc49" in CMakeLists.txt. With this change, FindBoost.cmake looked for, and found, my Boost library files.
You can also specify the version of Boost that you would like CMake to use by passing -DBOOST_INCLUDEDIR or -DBOOST_ROOT pointing to the location of correct version boost headers
Example:
cmake -DBOOST_ROOT=/opt/latestboost
This will also be useful when multiple boost versions are on the same system.
I also had a similar problem and discovered that the BOOST_INCLUDE_DIR, BOOST_LIBRARYDIR and BOOST_ROOT env variables must hold absolute paths.
HTH!
In my case Boost was not installed. I used below command on Mac and then cmake find_package(Boost) works like a charm
brew install Boost
Please note upper case 'B' in Boost!
If you are building your own boost do not forget to use the --layout=versioned otherwise the search for a particular version of library will fail
For cmake version 3.1.0-rc2 to pick up boost 1.57 specify -D_boost_TEST_VERSIONS=1.57
cmake version 3.1.0-rc2 defaults to boost<=1.56.0 as is seen using -DBoost_DEBUG=ON
cmake -D_boost_TEST_VERSIONS=1.57 -DBoost_DEBUG=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
One more bit of advice for anyone trying to build CGAL in particular, with statically linked Boost. It is not enough to define Boost_USE_STATIC_LIBS; it gets overridden by the time Boost_DEBUG outputs its value. The thing to do here is to check the "Advanced" checkbox and to enable CGAL_Boost_USE_STATIC_LIBS.
I had the same problem while trying to run make for a project after installing Boost version 1.66.0 on Ubuntu Trusty64. The error message was similar to (not exactly like) this one:
CMake Error at
/usr/local/Cellar/cmake/3.3.2/share/cmake/Modules/FindBoost.cmake:1245 (message):
Unable to find the requested Boost libraries.
Boost version: 0.0.0
Boost include path: /usr/include
Detected version of Boost is too old. Requested version was 1.36 (or newer).
Call Stack (most recent call first):
CMakeLists.txt:10 (FIND_PACKAGE)
Boost was definitely installed, but CMake couldn't detect it. After spending plenty of time tinkering with paths and environmental variables, I eventually ended up checking cmake itself for options and found the following:
--check-system-vars = Find problems with variable usage in system files
So I ran the following in the directory at issue:
sudo cmake --check-system-vars
which returned:
Also check system files when warning about unused and uninitialized variables.
-- Boost version: 1.66.0
-- Found the following Boost libraries:
-- system
-- filesystem
-- thread
-- date_time
-- chrono
-- regex
-- serialization
-- program_options
-- Found Git: /usr/bin/git
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/myproject
and resolved the issue.
See FindBoost.cmake first. The variables you set are the correct ones but they should be all uppercase.
Make sure the library architecture matches with CMake configuration.
cmake -A x64 ..
I suggest creating a minimal executable which only includes a Boost library to see if it compiles.
#include <iostream>
#include <boost/date_time.hpp>
int main() {
using namespace std;
using namespace boost::gregorian;
date today = day_clock::local_day();
cout << today << endl;
}
find_package(Boost REQUIRED COMPONENTS
date_time
)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})
add_executable(test_boost "test_boost.cpp")
target_link_libraries(test_boost Boost::date_time)
Start debugging by checking Boost_FOUND first.
message(STATUS "Boost_FOUND: ${Boost_FOUND}")
The version should be found even if no libraries are found. (Boost_VERSION)
If Boost_LIBRARY_DIRS becomes non-empty, it should compile.
I had the same problem, and none of the above solutions worked. Actually, the file include/boost/version.hpp could not be read (by the cmake script launched by jenkins).
I had to manually change the permission of the (boost) library (even though jenkins belongs to the group, but that is another problem linked to jenkins that I could not figure out):
chmod o+wx ${BOOST_ROOT} -R # allow reading/execution on the whole library
#chmod g+wx ${BOOST_ROOT} -R # this did not suffice, strangely, but it is another story I guess
This can also happen if CMAKE_FIND_ROOT_PATH is set as different from BOOST_ROOT.
I faced the same issue that in spite of setting BOOST_ROOT, I was getting the error.
But for cross compiling for ARM I was using Toolchain-android.cmake in which I had (for some reason):
set(BOOST_ROOT "/home/.../boost")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${SYSROOT}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${SYSROOT} -I${SYSROOT}/include/libcxx")
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS}")
set(CMAKE_FIND_ROOT_PATH "${SYSROOT}")
CMAKE_FIND_ROOT_PATH seems to be overriding BOOST_ROOT which was causing the issue.
For those using python3.7 docker image, this solved:
apt install libboost-system-dev libboost-thread-dev
Maybe
brew install boost
will help you.

Resources