I have tried following the tutorial Boost gives on their documentation for installing boost and have looked at a few other questions here to try to determine why I can't install Boost at a custom location. Perhaps I'm misunderstanding, but the --prefix option is supposed to specify where the Boost headers and libs will go, then bootstrapper.sh creates a .jam file that is used when b2 or bjam is run.
When I issue the following command
./bootstrap.sh --prefix="$HOME/dev/emulator/src/boost" --includedir=headers --libdir=dist --with-libraries=date_time
I see that the correct lines are added to the generated project-config.jam file
option.set prefix : /home/liam/dev/emulator/src/boost ;
option.set exec-prefix : /home/liam/dev/emulator/src/boost ;
option.set libdir : dist ;
option.set includedir : headers ;
However, when I run ./b2 as instructed by the documentation, it installs the Boost libraries to the source folder; i.e.
The following directory should be added to compiler include paths:
/home/liam/Downloads/brave/boost_1_66_0
The following directory should be added to linker library paths:
/home/liam/Downloads/brave/boost_1_66_0/stage/lib
And running ./b2 install gives me no file output to the intended directory either.
You need to use your directory in both steps:
DST_DIR=${HOME}/dev/emulator/src/boost
./bootstrap.sh --prefix=${DST_DIR} --includedir=headers --libdir=dist --with-libraries=date_time
./b2 --prefix=${DST_DIR} install
Try
./bootstrap.sh --prefix=path/to/installation/prefix
./b2 install
So that means first bootstrap b2 and then use it to build and install boost.
Related
So I could not compile the c++ code with this in its CMakeList.txt
find_package(Boost REQUIRED COMPONENTS program_options)
due to error output
Imported target "Boost::program_options" includes non-existent path
"/include"
in its INTERFACE_INCLUDE_DIRECTORIES.
I print out the variables BOOST_ROOT and Boost_INCLUDE_DIRS in boost_program_options-config.cmake (it is the file which the compiler error points to )
It turns out that BOOST_ROOT is "" and Boost_INCLUDE_DIRS points to "/include"
I believe this is the reason, the directory of the boost include file is under path /usr/include
What could I to set the BOOST_ROOT parameter permanently for all future build or better ways to fix this problem?
Following fellow coder's advises, I reinstalled the boost but the build error still persists.
What I did to reinstall boost was
remove the boost( I only have boost 1.71 install), commands on Ubuntu20.04 Terminal are:
:~$ sudo apt-get autoremove libboost1.71-dev
reinstall boost, commands are:
:~$ sudo apt-get install libboost-all-dev
I also checked the cmake version and it is cmake 3.16.3
The code is the ROS2's Nav2 package. With ROS2 already installed and running prefectly, the build commands I use to build the Nav2 package is
:~$ colcon build --symlink-install
This is the command that throws out the error
Imported ... Boost::program_options ... non-existent path ... INTERFACE_INCLUDE_DIRECTORIES
thanks ahead!
OK, so after some investigation over weekend the answer to resolving the problem becomes clear.
The cause of distress is two folds.
Firstly, ubuntu has shortcut to /usr/lib as lib at root directory /, which is the folder /lib.
Secondly, ubuntu's root directory does not have a /include folder that suppose to have all the headers etc.
So when building your codes. The cmake sets all your CMAKE_CURRENT_LIST_DIR with prefix "" instead of /usr
this is problematic because if you look at boost_program_options-config.cmake. The _BOOST_INCLUDEDIR is the value that sets the INTERFACE_INCLUDE_DIRECTORIES.
However, _BOOST_INCLUDEDIR is in turn set by CMAKE_CURRENT_LIST_DIR as prefix. Therefore you get a /<subfix> instead of /usr/<subfix>as your boost include folder directory.
cmake would find no such include folder of such directory. Thus outputting the question's error message.
To solve is simple, either delete the shortcut folder at root, or create shortcut folder that is linked to /usr/include .
My goal is to download the Boost repository if it isn't found and then build it the default way, i.e. using boostrap and b2 tools.
I know, I can download it like this:
include(FetchContent)
FetchContent_Declare(
Boost
PREFIX external_dependencies/boost
GIT_REPOSITORY https://github.com/boostorg/boost.git
GIT_SUBMODULES libs/system libs/serialization libs/random
libs/function libs/config libs/headers libs/assert libs/core libs/integer
libs/type_traits libs/mpl libs/throw_exception libs/preprocessor libs/utility
libs/static_assert libs/smart_ptr libs/predef libs/move libs/io libs/iterator
libs/detail libs/spirit libs/optional libs/type_index libs/container_hash
libs/array libs/bind
tools/build tools/boost_install
)
FetchContent_GetProperties(Boost)
FetchContent_Populate(Boost)
But how can I build it now correctly? I'd like to run following commands:
./bootstrap.sh
./b2 headers
./b2 -q cxxflags="-fPIC" --layout=system variant=${BUILD_TYPE} link=${LINK_TYPE} address-model=64 --with-system --with-serialization --with-random
I'm thinking about add_custom_target() and add_custom_command() functions, but I'm not sure, if it's the recommended way to do this.
add_custom_target is probably better because it is declaring a target that is convenient to depend on,
using add_dependencies.
You may need one target per command, and that becomes quickly annoying. So instead I would try (I did not) writing a script performing the build, let's call it build-boost.sh:
#!/bin/bash
# This is meant to be run from the source directory of Boost.
./bootstrap.sh
./b2 headers
./b2 -q cxxflags="-fPIC" --layout=system variant=$2 link=$3 address-model=64 --with-system --with-serialization --with-random
./b2 install --prefix=$4
In your CMake code, you would be calling it this way:
add_custom_target(
build-boost
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build-boost.sh ${BUILD_TYPE} ${LINK_TYPE} ${CMAKE_CURRENT_BINARY_DIR}/external_dependencies/boost-installation
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/external_dependencies/boost
)
After that, you are not done yet.
You should still export all the variables FindBoost usually exports, and create all expected directories in advance (under ${CMAKE_CURRENT_BINARY_DIR}/external_dependencies/boost-installation), since at configuration time the binaries and headers are not present yet.
If you complete this work, please let the community know, since this can be helpful.
In order to install graph-tool, I must install dependencies with autoconf.
Some of these dependencies use boost, and I link my local boost install to these dependencies with:
export BOOST_ROOT=/my/path/boost
./configure
And everything proceeds smoothly. Then, when I shift to graph tool, I get a prompt to add BOOST_ROOT for an "unstaged boost". I don't know what that means, so I try:
export BOOST_ROOT=/my/path/boost
./configure
And this fails. I then inspect graph-tool's configure script, and it seems like, during the test for boost, it checks the following path:
if test -n "$BOOST_ROOT" ; then
for libsubdir in $libsubdirs ; do
if ls "$BOOST_ROOT/stage/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
done
And I review both my boost install and my boost source code checkout, and I see no paths from the boost root directory with "stage" in them.
This seems strange, given that the dependencies were able to include the local boost install using the autoconfigurer. Are there some simple edits I need to make?
I am trying to follow this tutorial on wrapping C++ code for python for Windows.I installed python.Downloaded the latest version of boost(1_55).First I ran bootstrap.bat to build bjam.exe.Next, I configured boost_1_55_0\tools\build\v2\user-config.jam to use msvc10 compiler and added the path to python installation.
Now,based on the tutorial :
Now we are ready... Be sure to cd to libs/python/example/tutorial
where the tutorial "hello.cpp" and the "Jamroot" is situated.
Finally:
bjam
Trying to run bjam in that directory gives me : "bjam is not recognized as internal or external command" error.What have I missed here? Should user-config.jam reside in another location?Or bjam added to system path?
UPDATE:
Ok.Thanks to #john I had to add bjam to system path.But now,running it,hello_ext.lib is created in \boost_1_55_0\libs\python\example\tutorial\bin\msvc-11.0\debug but not DLL.Based on the tutorial I should get DLL file for the extension.Now, I am not sure how python links with extension.But if I assume it does like C++ then it should have linked with hello_ext.lib.But if run :
python hello.py
which contains imported method from the extension ,the python runtime crashes.Isn't there a comprehensive tutorial on this workflow?Boost doc sucks completely on this.
This worked for me:
1.) unzip boost_1_55_0.zip
2.) Prepare to use the Boost Library Binaries
Go to the boost_1_55_0 root directory and open a command prompt and type following commands:
Bootstrap
3.) Find user-config.jam:
Type following in the command prompt:
ECHO %HOMEDRIVE%%HOMEPATH%
4.) If the user-config.jam is in your homedrive directory please change it there as followed:
ATTENTION:
The .jam language rates a “whitespace” as a separation of arguments!
# -------------------
# MSVC configuration.
# -------------------
# Configure msvc (default version, searched for in standard locations and PATH).
# using msvc ;
# Configure specific msvc version (searched for in standard locations and PATH).
using msvc : 10.0 : C:\\app\\tools\\MSVisualStudio2010\\VC\\bin\\cl.exe ;
….
# ---------------------
# Python configuration.
# ---------------------
# Configure specific Python version.
# using python : 3.1 : /usr/bin/python3 : /usr/include/python3.1 : /usr/lib ;
using python
: 2.5 # Version
: C:\\app\\tools\\Python25\\python.exe # Python Path
: C:\\app\\tools\\Python25\\include # include path
: C:\\app\\tools\\Python25\\libs # lib path(s)
: <define>BOOST_ALL_NO_LIB=1
;
5.) Build the Libraries AFTER configuration!!
Go to the boost_1_55_0 root directory and open a command prompt and type following commands:
.\b2
6.) Copy the user-config.jam to \boost_1_55_0\libs\python\example\tutorial
7.) Go further to \boost_1_55_0\stage\lib\
Rename libboost_python-vc100-mt-gd-1_55.lib to boost_python-vc100-mt-gd-1_55.lib and copy it to
\boost_1_55_0\libs\python\example\tutorial
8.) Now you should have all of these files in the \boost_1_55_0\libs\python\example\tutorial directory
hello.cpp
hello.py
user-config.jam
Jamroot
boost_python-vc100-mt-gd-1_55.lib
bjam.exe
9.) Open a command prompt in \boost_1_55_0\libs\python\example\tutorial
And type following command:
bjam
10.) After successful building..
You should have this file in the directory:
hello_ext.dll
rename this file to:
hello_ext.pyd
I'm trying to build only a subset of boost libraries. For example, I have this code:
test.cpp:
#include <boost/thread.hpp>
int main (){
return 0;
}
I then do
./bcp --scan test.cpp ~/dev/boost_compact/
So the dependencies files are copied to ~/dev/boost_compact/boost.
Then, following this answer, I copy all files at the root of a regular boost and also the tools directory and run
./bootstrap
./bjam
./bjam install
This does copy all the headers to a destination directory, but it does not build/copy the libraries. This same set of actions does work in the full boost. What am I doing wrong?
Solved the problem. The reason the libraries were not being copied was that I was using the wrong boost directory, that is
./bcp --scan --boost=<path to boost build directory> test.cpp ~/dev/boost_compact/
when I should be using
./bcp --scan --boost=<path to boost source directory> test.cpp ~/dev/boost_compact/
If now you run
./bootstrap
./bjam
./bjam install
The libraries will be build.
Maybe a permission issue?
or
Perhaps try explicitly setting the libdir?
bjam --libdir=path/to/lib install