Building boost-python example - c++

I'm running Ubuntu 13.10 . I installed libboost1.54-dev.
I did a Git checkout of Boost, and did a checkout to "boost-1.54.0".
I changed directories to boost/libs/python/example/tutorial in the source.
I ran "bjam". I get:
$ bjam
Unable to load Boost.Build: could not find build system.
---------------------------------------------------------
/home/dustin/build/boost/libs/python/example/boost-build.jam attempted to load the build system by invoking
'boost-build ../../../tools/build/v2 ;'
but we were unable to find "bootstrap.jam" in the specified directory
or in BOOST_BUILD_PATH (searching /home/dustin/build/boost/libs/python/example/../../../tools/build/v2, /usr/share/boost-build).
Please consult the documentation at 'http://www.boost.org'.
There are only three files in the example directory:
-rw-r--r-- 1 dustin dustin 484 Mar 1 12:59 hello.cpp
-rwxr-xr-x 1 dustin dustin 275 Mar 1 12:59 hello.py
-rw-r--r-- 1 dustin dustin 1445 Mar 1 15:43 Jamroot
The directions say that it should be just that easy: http://www.boost.org/doc/libs/1_54_0/libs/python/doc/tutorial/doc/html/python/hello.html
The last few lines of the strace is:
openat(AT_FDCWD, "/home/dustin/build/boost/libs/python/example/tutorial", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/home/dustin/build/boost/libs/python/example", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/share/boost-build", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
open("/home/dustin/build/boost/libs/python/example/boost-build.jam", O_RDONLY) = 3
Why is it looking for boost-build.jam? What am I missing?

You can create your own boost-build.jam. For quickstart example (which is broke) just create a file called boost-build.jam with this in it and make sure it points to the src directory. It is discussed here http://lists.boost.org/boost-build/2014/11/27738.php
# Edit this path to point at the tools/build/v2 subdirectory of your
# Boost installation. Absolute paths work, too.
boost-build ../../../../tools/build/src ;

In essence, bjam is an interpreter, and Boost.Build is a build system written in bjam files. When bjam starts, it will attempt to locate the jam files for Boost.Build. In this case, bjam attempted to locate boost-build.jam relative to the tutorial and errors when it is missing. To build the tutorial, either:
Verify that the boost/tools/build submodule has been initialized from within the boost git repository. Boost.Python has other dependencies, so it may be easier to initialize all submodules. This will allow the bjam interpreter installed from the libboost1.54-dev package to locate Boost.Build from within the repository, and build the tutorial and its dependencies.
To build against packaged libraries:
Install the libboost1.54 package. This will install the Boost.Python shared library and its dependencies.
Modify the tutorial's Jamroot file. It should no longer attempt to use the boost project, and should explicitly list the Boost.Python shared library path:
-# Specify the path to the Boost project. If you move this project,
-# adjust this path to refer to the Boost root directory.
-use-project boost
- : ../../../.. ;
-
# Set up the project-wide requirements that everything uses the
-# boost_python library from the project whose global ID is
-# /boost/python.
+# boost_python library.
project
- : requirements <library>/boost/python//boost_python ;
+ : requirements <library>/usr/lib/libboost_python-py27.so ;
The library path and name may need to be changed based on where the libboost-python1.54-dev packaged installed the Boost.Python library.
Set the BOOST_BUILD_PATH environment variable to /usr/share/boost-build/kernel or wherever the libboost1.54-dev package installed boost-build.jam.

Related

could not find "vswhere"

I'm trying to install boost to run PyGMO properly. However, after I unpack it in a directory (did not use git).
After running bootstrap vc142 (I'm using VScode V1.63.2 and I'm on windows). I'm getting this error:
Building Boost.Build engine
LOCALAPPDATA=C:\Users\wojci\AppData\Local
could not find "vswhere"
Call_If_Exists "..\bin\VCVARS32.BAT"
###
### Using 'msvc' toolset.
###
Followed by:
C:\Program Files\boost\boost_1_78_0\tools\build\src\engine>dir *.exe
Volume in drive C has no label.
C:\Program Files\boost\boost_1_78_0\tools\build\src\engine>copy /b .\b2.exe .\bjam.exe
The system cannot find the file specified.
Failed to build Boost.Build engine.
Does anyone know how to fix/work around this?
Thank you in advance
I found the solution here (git)
Prerequisites:
First download and install MinGW installer mingw-w64-install.exe (I fot it from Sourceforge) and make sure you use x86_64 architecture.
Then download the boost file (boost_1_78_0.zip source)
Open and run cmd as admin
Enter the following command to link the MinFW folder in C:\
mklink /J C:\MinGW "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64"
add MinGW to the system PATH:
set PATH=%PATH%;C:\MinGW\bin
setx /M PATH "%PATH%"
Check if you have at least g++ version of 8.1.0
g++ --version
Methodology to install boost:
Navigate to the install folder created and unzip and extract the boost_1_78_0.zip file into this folder
In the CMD navigated to the boost folder
cd C:\install\boost_1_78_0
Type the following to make directories for building and installing boost
mkdir C:\boost-build
mkdir C:\install\boost_1_78_0\boost-build
mkdir C:\boost
Setup boost.build (second line prepers b2, the third line builds boost.build with b2, and the fourth line adds C:\boost-build\bin to your session PATH variable)
cd C:\install\boost_1_78_0\tools\build
bootstrap.bat gcc
b2 --prefix="C:\boost-build" install
set PATH=%PATH%;C:\boost-build\bin
building boost (first line navigateds to boost directory, second line builds boost with b2 this can take a while)
cd C:\install\boost_1_78_0
b2 --build-dir="C:\install\boost_1_78_0\build" --build-type=complete --prefix="C:\boost" toolset=gcc install
Extra notes:
This should work for boost 1.68.0 too and might work for other version just replace 1_78_0 with 1_68_0.
At the end you should have three lines that look something like this:
...failed updating 72 targets...
...skipped 292 targets...
...updated 22164 targets...
It's totally fine if you have some failed and skipped files.
Type "native tools " in the start search.
Run "Native tools for visual studio" as an administrator. A command prompt opens.
change directory to boost .
run command "bootstrap".
Follow up by ".\b2".
Wait for a while.
Worked for me. Hope it helps.

Executable missing full library path after build

I am using CMake to compile an executable that is linked against several libraries that I have built and installed into a local project directory (libs/3rdparty). Note that this is prior to installation of the project, primarily for the purpose of running unit tests and debugging. The problem I am having is that sometimes there is a library that is linked, but the executable is missing the path to the library. The library I am currently having an issue with is leptonica. However, I have run into this issue several times with different libraries on different platforms (osx, fedora, centos, ubuntu). Through research I have seen similar issues, but I have never been able to find a definitive answer of why the full path to the library would be missing.
I've tried playing with:
CMAKE_BUILD_WITH_INSTALL_RPATH
CMAKE_INSTALL_RPATH
CMAKE_INSTALL_RPATH_USE_LINK_PATH
and these don't seem to have much effect.
My CMakeLists contains:
find_package(Leptonica REQUIRED)
target_link_libraries(${target}
PRIVATE
...
${Leptonica_LIBRARIES}
)
Here is the output from ldd on one of the unit test executables:
ldd test_utilities
...
libleptonica.so.5.3.0 => not found
libtesseract.so.4 => {MY PROJECT}/libs/3rdparty/tesseract/lib/libtesseract.so.4
leptonica is the only library that is not found out of ~30 other libraries.
Does anyone know what the root cause of this problem is? I am not looking to work around the problem by modifying LD_LIBRARY_PATH.
-- Added LeptonicaTargets-release.cmake. According to this the full path to the lib should be in the target.
#----------------------------------------------------------------
# Generated CMake target import file for configuration "RELEASE".
#----------------------------------------------------------------
# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)
# Import target "leptonica" for configuration "RELEASE"
set_property(TARGET leptonica APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(leptonica PROPERTIES
IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE "/usr/lib/x86_64-linux-gnu/libpng.so;/usr/lib/x86_64-linux-gnu/libz.so;m"
IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/libleptonica.so.1.77.0"
IMPORTED_SONAME_RELEASE "libleptonica.so.5.3.0"
)
list(APPEND _IMPORT_CHECK_TARGETS leptonica )
list(APPEND _IMPORT_CHECK_FILES_FOR_leptonica "${_IMPORT_PREFIX}/lib/libleptonica.so.1.77.0" )
# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
Here are the files in the leptonica/lib directory:
ll libs/3rdparty/leptonica/lib/
total 2776
drwxr-xr-x 3 user user 4096 May 30 14:17 ./
drwxr-xr-x 5 user user 4096 May 30 14:17 ../
lrwxrwxrwx 1 user user 21 May 30 14:17 libleptonica.so -> libleptonica.so.5.3.0
-rw-r--r-- 1 user user 2829784 May 30 09:49 libleptonica.so.1.77.0
lrwxrwxrwx 1 user user 22 May 30 14:17 libleptonica.so.5.3.0 -> libleptonica.so.1.77.0
drwxr-xr-x 2 user user 4096 May 30 14:17 pkgconfig/
Output from chrpath --list test_utilities appears to contain the correct path to the library as well:
chrpath --list test_utilities
test_utilities: RUNPATH=...:{MY PROJECT}/libs/3rdparty/leptonica/lib:...
For anyone who runs across this, I have finally figured it out.
The issue was related to the library being a transitive dependency of OpenCV. On Ubuntu, ld now defaults to using using --enable-new-dtags which uses RUNPATH, not RPATH. There is an issue where RUNPATH is not searched for transitive dependencies.
See https://bugs.launchpad.net/ubuntu/+source/eglibc/+bug/1253638
Simply adding "-Wl,--disable-new-dtags" to the target linker options resolved my issue. All libraries are now found, including other libraries than leptonica that I added today. I am sure that I will likely have to make changes when building a package for installation though.

Third party SCIP files was not found when I build the source code of OR-Tools in compile OR-Tools using tools\make cc

I have made new file 'Makefile.local' and add "WINDOWS_SCIP_DIR=c:/Program Files/SCIPOptSuite" to the file.
SCIP is also compiled and the file path is correct.
We have recently updated the installation instructions here:
https://developers.google.com/optimization/install/cpp/source_windows
Can you check them against what you did?
Thanks
You must use a path without space since Makefile can't support it everywhere on a windows prompt (e.g. wildcard function in Makefile inside a if command).
if you have installed SCIP using the SCIPOptSuite 6.0.2 64bits Windows installer it should be located in %ProgramFiles%\SCIPOptSuite 6.0.2 first you need to find the short name version for each directories
dir "%ProgramFiles%*" /x
...
Directory of C:\
01/06/2020 10:35 AM <DIR> PROGRA~1 Program Files
dir "%ProgramFiles%\SCIP*" /x
...
01/06/2020 10:35 AM <DIR> SCIPOP~1.2 SCIPOptSuite 6.0.2
so in my case I can use:
set WINDOWS_SCIP_DIR=C:\PROGRA~1\SCIPOP~1.2
then you can check using:
cd <path_to_your_ortools_source_install>
set PATH=%PATH%;tools;tools\win
make check_third_party
to test you can run the sample examples/integer_programming.cc using:
make rcc_integer_programming

Graph-tool: compile and connect to local CGAL library, in Linux? (no sudo)

[Ubuntu]
I have compiled CGAL locally:
/path/to/cgal/
/lib/
libCGAL_Core.so libCGAL_Core.so.13.0.2
libCGAL_ImageIO.so.13 libCGAL.so libCGAL.so.13.0.2
libCGAL_Core.so.13 libCGAL_ImageIO.so
libCGAL_ImageIO.so.13.0.2 libCGAL.so.13
/include/
/CGAL/
version.h compiler_config.h
And I have managed to satisfy all of the graph-tool requirements except cgal (at least all of the requirements checked up to cgal):
./configure --with-boost=/path/to/boost --with-cgal=/path/to/cgal
And I get all successes up and until I get the following error message:
checking for __gmpz_init in -lgmp... yes
checking for __gmpz_init in -lgmp... (cached) yes
checking whether CGAL is available in /path/to/cgal... no
configure: error: CGAL library not found.
// the harshest part is that it seems to be searching in the correct
// directory.
I have tried specifying different points in the cgal build directory. The cgal compilation command I used was (from build directory):
cmake path/to/cgal_src_dir -DCMAKE_BUILD_TYPE=Release;
Next, I tried adding includes:
./configure --with-boost=$boost --with-cgal=path/to/cgal CPPFLAGS="-I path/to/cgal/include -I $HOME/.local/include" LDFLAGS="-L path/to/cgal/lib -L $HOME/.local/lib -Wl,-rpath=$HOME/.local/lib"
I will admit that I don't understand the -Wl,-rpath= part, I copied that from the graph-tool installation guide. The .local/lib folder contains the files for the other components, such as gmp, expat, sparsehash, etc.
This is not exact answer but as asked by OP will help in finishing installation, so please don't vote blindly.
To create debian package of libcgal open your CMakeList.txt and at the end of file add:
#--------------------------------------------------------------------
# Create debian files
#--------------------------------------------------------------------
if (UNIX AND NOT APPLE)
SET(CPACK_GENERATOR "DEB")
SET(CPACK_PACKAGE_NAME "libcgal-all")
SET(CPACK_PACKAGE_VERSION "${CGAL_VERSION}")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C++ library for computational geometry (development files)\n CGAL (Computational Geometry Algorithms Library) makes the most important of the solutions and methods developed in computational geometry available to users in industry and academia in a C++ library. The goal is to provide easy access to useful, reliable geometric algorithms.\n .\n This package contains the header files and static libraries for libCGAL.so, libCGAL_Core.so, and libCGAL_ImageIO.so. The header files and static libraries for libCGAL_Qt4.so can be found in the package libcgal-qt4-dev.")
SET(CPACK_PACKAGE_CONTACT "bordeo")
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libboost-dev, libboost-thread-dev, libboost-system-dev, libboost-program-options-dev, libgmp10-dev, libmpfr-dev, zlib1g-dev")
SET(CPACK_DEBIAN_PACKAGE_REPLACES "libcgal10, libcgal-dev")
INCLUDE(CPack)
endif()
In case you don't have any dependency remove whole line of SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libcln6, libcln-dev, libreadline6, libreadline6-dev, flex, bison"), and change others as it seems fit.
Now go to the terminal and issue following commands in cgal directory
mkdir build
cd build
cmake-gui ..
# set CMAKE_INSTALL_PREFIX to `~/.local
cmake ..
make -j4
cpack ..
you will find your debian built. Extract or install the debian to ~/.local.
Once this is done go to graph tool directory and start the build like
./configure --prefix="/wherever" --with-boost=/path/to/boost --with-cgal=~/.local
make -j4
make install
Hope this will solve your problem.

Can't run bjam to compile boost python tutorial

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