Jamroot file for building python module with boost python - boost

I build boost library as it was said here
It didn't install bjam so I use b2 executable as I read that it is mostly the same.
I wrote my module in C++. Whole project hierarchy:
boost
b2
build
include
...
lib
...
project
lib
...
include
...
Jamroot
myclass.h
myclass.cpp
mymodule.cpp(for 'BOOST_PYTHON_MODULE(mymodule)...')
Now I need to write Jamroot and include all dependencies there.
use-project boost
: "*path_to_boost_here*/boost/build" ;
lib boost_python ;
exe mymodule
: mymodule.cpp
: requirements
<include>".../boost/build/include"
<include>"/usr/include/python3.6"
<include>"include"
<library>boost_python
;
This is my current Jamroot. But calling b2 gives:
error: Unable to load Jamfile.
error: Could not find a Jamfile in directory '*path_to_boost_here*/boost/build'.
How should I include every '.h' and '.so' which I need and boost python?

Related

Library's CMake generates DLL. Application's CMake wants LIB

My library has minimal, straightforward CMake code with the pertinent lines
add_library(MyLib <sources>)
install(
TARGETS MyLib
LIBRARY DESTINATION ${destination}/lib
RUNTIME DESTINATION ${destination}/lib
COMPONENT Libraries)
install(
FILES mylib.h
DESTINATION ${destination}/include
COMPONENT Headers)
When executed under Windows, the system generates mylib.dll in ...\build\Release, and mylib.lib and mylib.exp (what's that?) in ...\build\lib\Release. It only installs mylib.dll.
My application has minimal, straightforward CMake code to search for my library:
find_path(MyLib_INCLUDE_DIR mylib.h)
find_library(MyLib_LIBRARIES NAMES MyLib)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MyLib DEFAULT_MSG MyLib_LIBRARIES MyLib_INCLUDE_DIR)
Which works under Linux, but under Windows results in
-- Could NOT find MyLib (missing: MyLib_LIBRARIES)
From experimentation I know that this error occurs whenever there is only a .DLL file, and no associated .LIB import library.
Shall I correct MyLib to install mylib.lib? How?
Or is it possible to modify my application so that it is satisfied with mylib.dll only? How?
Research done so far
This is not about static vs dynamic linking (DLL and LIB files - what and why?, cmake link against dll/lib): I want dynamic linking; if a .LIB file is required, it has nothing to do with static linking.
This link cmake : shared library : how to get the .lib name instead of .dll name? may be pertinent, but is not explicit enough. Two other questions CMake generated VS project expecting lib instead of dll, Linking dll/lib to a cmake project seem related, but have no answer.
Command install classifies .lib file for a shared library as ARCHIVE. This is explicitly stated in the documentation:
For DLL platforms (all Windows-based systems including Cygwin), the DLL import library is treated as an ARCHIVE target.
So you need to add ARCHIVE clause to install() for install .lib file as well:
install(
TARGETS MyLib
ARCHIVE DESTINATION ${destination}/lib
LIBRARY DESTINATION ${destination}/lib
RUNTIME DESTINATION ${destination}/bin
COMPONENT Libraries)
Not also, that RUNTIME DESTINATION is usually specified as bin, the same as destination for executables. This helps the executables on Windows to locate the shared libraries (.dll).

macOS x: boost .hpp not found compiling qt5 project with make

I am trying to build an example qt5 project where Makefile is built with qmake. clang++ gives me this error:
fatal error: 'boost/numeric/ublas/vector.hpp' file not found
Since Makefile is generated by qmake, it is difficult edit the huge Makefile -I include paths to find boost header files ( which is in /usr/local/include/boost ).
Is there a way to specify additional include paths in qmake that would help?
Sure, you can add include paths to the qmake file using INCLUDE_PATH
http://doc.qt.io/qt-5/qmake-variable-reference.html#includepath
# add homebrew include path only on MacOS
macx:INCLUDEPATH += "/usr/local/include"

boost library 1.47.1 build 'lib' prefix causing LNK1104 error

I'm having difficulties generating the correct boost .lib file to compile with a VS project I've been given. It appears that after performing the complete build installation using 'b2.exe' from VS2010 command prompt I'm only able to generate the boost library files that contain the 'lib' prefix.
When I come to compile my project I'm getting the following error message:
"error LNK1104: cannot open file 'boost_signals-vc90-mt-1_47.lib'"
After going through the lib folder I can see that my boost build has only generated 'libboost_signals-vc90-mt-1_47.lib'
The boost documentation gives the following information about the lib prefix:
lib
Prefix: except on Microsoft Windows, every Boost library name begins with this string. On Windows, only ordinary static libraries use the lib prefix; import libraries and DLLs do not.
So far I've attempted the following build options for the msvc-9.0 toolset:
'build-type=complete'
'link=static,shared'
Any advice on how I may be able to generate the required .lib file would be greatly appreciated.
Many Thanks.
link=static should be used whenever you're linking to static version of boost library.
link=shared - should be used whenever you're linking dynamically to boost. It will add extra dependencies on boost dll's.
You can also use link=static,shared to build both versions - static and dynamic.
Define 'BOOST_ALL_DYN_LINK' in project controls how you link to boost.
If it's defined - it's dynamic linking, if not defined - it's static linking.

How compile a DLL which is using boost library?

I'm working on a DLL project in VS 2010, I want to use boost mutex in some part of my code. but when I compile project to release final DLL, I get this linkage error:
LINK : fatal error LNK1104: cannot open file 'libboost_date_time-vc100-mt-1_49.lib'
I've already compiled boost with this command:
bjam install --toolset=msvc variant=release link=static threading=multi runtime-link=static
& I've a file named libboost_date_time-vc100-mt-s-1_49.lib, when I change configuration type of my project from Dynamic Linked Library (DLL) to Static Library, the project builds successfully, but I need to release only as a DLL file (& my final DLL CAN NOT have any dependency to other external DLLs). I know the problem causes by compilation of boost, but I don't know how should I recompile it
Any guideline?
Check that you link the runtime-library statically (Configuration properties-->C/C++-->Code generation-->Runtime library: Multi-threaded (/MT).
Otherwise, link CRT and boost dynamically. For this purpose build boost like this:
bjam --toolset=msvc variant=release link=shared threading=multi runtime-link=shared
IMO, you built the boost library just fine : you used link=static which means you would like to emit static library (and not a DLL) and since you would like to have standalone deployment , you specified runtime-link=static meaning you link against MS C/C++ run time as static libraries (e.g. the code for printf() will be embedded in your final library and not be referenced to msvcr100.dll)
Please take a look at the picture below, make sure to set the full path of the directory where your boost library resides under Additional Library Dependencies
I fixed my error "Error LNK1104 cannot open file 'libboost_locale-vc142-mt-gd-x32-1_73.lib'" in a DLL project, which I described in this issue on boost' github by installing the boost library using vcpkg.
Install vcpkg. Then write .\vcpkg install boost. You can see how it's done in the video: https://youtu.be/b7SdgK7Y510 . He's not installing the boost library but the process is exactly the same.
This is all for Windows and Visual Studio's toolset, of course.

CMake - Issue with static library

I'm using CMake-2.8 on winxp with Visual Studio 2005 generator.
lets say I've a dll created (A.dll) from some cxx files and a static library static.lib
So I call Link_Directories to specify the directory where the static library is located.
Now A.dll is built fine.
Now I want B.dll built from some cxx sources, A.lib (the import lib of A.dll)
Now when I say Target_Link_Libraries for (B A), the project file is created with static.lib also as a dependency.
Now B has two dependencies A and static.lib. But I'm not adding the directory of static.lib to Link_Directories for B and my build fails.
I do not think B needs to know about static.lib
Any Ideas how to avoid this ?
Thanks in advance,
Surya
From the CMake docs:
Library dependencies are transitive by default. When this target is linked into another target then the libraries linked to this target will appear on the link line for the other target too. See the LINK_INTERFACE_LIBRARIES target property to override the set of transitive link dependencies for a target.
Hence, this should solve your problem:
TARGET_LINK_LIBRARIES(B LINK_INTERFACE_LIBRARIES A)

Resources