Building a subset of boost libraries - c++

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

Related

Compiling and Running CGAL Triangulation Demo

I am trying to use the CGAL library to display a 2D Delaunay triangulation, like in the example here
My code looks like this:
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/draw_triangulation_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K> Triangulation;
typedef Triangulation::Point Point;
int main(void){
Point a(1,1), b(2,1), c(2,2), d(1,2);
Triangulation T;
T.insert(a);
T.insert(b);
T.insert(c);
T.insert(d);
CGAL::draw(T);
return 0;
}
When I try to compile this code with g++ -o cgalTest.exe cgalTest.cpp -lCGAL -lgmp the program compiles successfully, but on runtime I get Impossible to draw because CGAL_USE_BASIC_VIEWER is not defined
By searching on Google, I found someone that suggested using g++ -o cgalTest.exe cgalTest.cpp -lCGAL -lgmp -DCGAL_USE_BASIC_VIEWER which produces the following error on compile time: /usr/include/CGAL/Qt/Basic_viewer_qt.h:30:10: fatal error: QApplication: No such file or directory #include <QApplication>
I am using ubuntu 19.04, so I installed CGAl using sudo apt-get install libcgal-dev and sudo apt-get install libcgal-qt5-dev
I tried to install sudo apt-get install libqt5svg5-dev libqt5opengl5-dev as well to solve the error, but to no avail.
Do I need to install additional libraries? Maybe the compilation must be done differently?
Thank you
Ok, for anyone facing the same problem, here is how I solved it:
First, I used the locate QApplication command to find the location of the QApplication header file on my system. Be sure to run sudo updatedb before using locate. If locate doesn't find the location of QApplication then you are missing qt libraries. Try sudo apt-get install qt5-default and the other libraries I mentioned in my question, run sudo updatedb and try locate QApplication again.
When you find the path to QApplication just use the -I option to instruct the compiler to use it. Here is an example g++ -o delaunayTest delaunayTest.cpp -lCGAL -lgmp -lCGAL_Qt5 -DCGAL_USE_BASIC_VIEWER -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets/ (because in my case, QApplication was inside the directory /usr/include/x86_64-linux-gnu/qt5/QtWidgets/)
Trying to compile with this, you will probably get another header file error. Repeat the same process using locate until you get no more header file errors.
At that point, you will likely encounter an undefined reference to symbol error.
To solve this, use locate again to find the location of the file that caused the error (for example libQt5OpenGL.so.5) and add the path to the compilation command as is (for example g++ -o delaunayTest delaunayTest.cpp /usr/lib/x86_64-linux-gnu/libQt5OpenGL.so.5) along with all the previous options.
You will probably get several undefined reference to symbol errors as well. Just keep using the same method until you don't get any.
At this point the program should compile properly and run properly.
Note that if you have multiple versions of qt installed, then the above might not work properly (If for example you have software that uses qt like MATLAB or anaconda installed in your system. You will know because locate will produce many paths for each file on the steps above). In such a case, I suggest building a Virtual Machine, downloading the CGAL libraries and qt5-default and following the above steps there, since it is very likely this won't work in a system with multiple qt installations.
Another option (maybe the easiest), using CMake, is to generate the file using the builtin script:
From the source file directory, run cgal_create_CMakeLists -c Qt5
Edit the generated CMakeLists.txt adding the line add_definitions(-DCGAL_USE_BASIC_VIEWER)
My generated and edited CMakeLists.txt:
# Created by the script cgal_create_CMakeLists
# This is the CMake script for compiling a set of CGAL applications.
cmake_minimum_required(VERSION 3.1...3.15)
project( tmp_cgal )
# CGAL and its components
find_package( CGAL QUIET COMPONENTS Qt5 )
if ( NOT CGAL_FOUND )
message(STATUS "This project requires the CGAL library, and will not be compiled.")
return()
endif()
add_definitions(-DCGAL_USE_BASIC_VIEWER) # <==== I've added this
# Boost and its components
find_package( Boost REQUIRED )
if ( NOT Boost_FOUND )
message(STATUS "This project requires the Boost library, and will not be compiled.")
return()
endif()
# include for local directory
# include for local package
# Creating entries for all C++ files with "main" routine
# ##########################################################
create_single_source_cgal_program( "b.cpp" )
Create a build directory: mkdir build
Change directory: cd build
Generate the build files: cmake ..
Build: make
Run the binary file. For me it's ./b because my source file was b.cpp
Environment:
These instructions should work for an Ubuntu 20.04.1 (or similar) with the packages libcgal-dev, libcgal-qt5-dev and qtbase5-dev installed (and, of course, cmake, make and g++).
Main references:
doc1 and doc2

Installing Boost to custom directory

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.

Simple installation from source on Linux

I'm trying to figure out a simplified way for installing C and C++ code
and libraries built from them, primarily for Linux. I think GNU Autotools, CMake, etc. would be overkill for what I'm trying to do.
An example: I've written some code which, when 'make' is run, builds to
create a library 'example.a'. (I'm going with static linking thus far.
Shared libraries will introduce still more issues; I'll crawl before I walk.) Use of the functions requires including 'example1.h', 'example2.h', etc.
With Autotools, one would run 'make install' or 'sudo make install' to
copy example.a to /usr/local/lib and the include files to /usr/local/include.
If executables had been built, those would get copied to /usr/local/bin.
I've tried adding the following lines to my makefile:
install:
cp example.a /usr/local/lib
cp example1.h /usr/local/include
cp example2.h /usr/local/include
cp example /usr/local/bin
This seems to work, mostly. Other projects are then able to "see"
the .h files and build correctly. But the .a file is not found; the only
way to get it to be linked is to explicitly give the path as
/usr/local/lib/example.a. (Though gcc insists it's looking for libraries
in that path.) So:
Question 1: Should my user-built libraries be put in /usr/local/lib? Or am
I using the wrong directory?
Now, my next problem: this has to be done with 'sudo make install'.
I'm thinking that for some projects of this ilk, where only one user will
be making use of the code in question, the libraries should go someplace
such as $HOME/lib, include files to $HOME/include, executables to
$HOME/bin.
Question 2: Is there a "standard" way to install includes/libraries for
just the current user, rather than doing so for all users? (Thus avoiding
the need for root use, and I'd think it would be a "cleaner" system if only
the user using the program had to deal with these files.)
You should probably use install to copy with explicit permissions. example.a probably isn't being found because it doesn't start with lib (a stupid requirement, I know).
Putting your lib, include, and bin under $HOME/.local is probably the closest thing to a per-user standard setup.
Edit:
I just tested it and it /usr/local/lib works fine for me:
foo.c
#include <stdio.h>
void foo() { puts("foo"); }
Compile and install:
gcc -c foo.c
ar crs libfoo.a foo.o
install -m 0755 /usr/local/lib #0644 should do too
In a different directory:
main.c
void foo(void);
int main() { foo(); return 0; }
Compile, link, and run:
gcc main.c -lfoo
./a.out

boost::regex linking issue in Xcode 4.5.2

I am sure this question has been asked in many different guises ( apologies in advance )-
I am using Xcode 4.5.2
Very simple does-nothing terminal application as follow...
#include <boost/regex.hpp>
int main(int argc, const char * argv[])
{
boost::regex regday_pattern("\\");
return 0;
}
Appreciate that regex in boost requires a library and not just a boost header. Being relatively new to xcode and the unix environment underneath I am a little confused as to how I need my setup so that I don't get the following linking error...
Undefined symbols for architecture x86_64:
"boost::basic_regex
Any help on this issue will be gratefully appreciated - I have read several responses to similar questions and have had trouble mapping those to my situation.
TIA
You are probably getting a linker error because you didn't actually build the Boost.Regex libraries.
Please follow the build instructions from the Boost documentation:
Issue the following commands in the shell (don't type $; that
represents the shell's prompt):
$ cd path/to/boost_1_53_0
$ ./bootstrap.sh --help
Select your
configuration options and invoke ./bootstrap.sh again without the
--help option. Unless you have write permission in your system's /usr/local/ directory, you'll probably want to at least use
$ ./bootstrap.sh --prefix=path/to/installation/prefix
to install
somewhere else. Also, consider using the --show-libraries and
--with-libraries=library-name-list options to limit the long wait you'll experience if you build everything. Finally,
$ ./b2 install
will leave Boost binaries in the lib/ subdirectory of
your installation prefix. You will also find a copy of the Boost
headers in the include/ subdirectory of the installation prefix, so
you can henceforth use that directory as an #include path in place of
the Boost root directory.
Finally, make sure that you can build and run the Regex example from the Boost documentation.

Makefile which link to library in C++

Recently, I try to create an makefile as below:
all:
g++ test.cpp -o Test
It creates an runnable Test. However, If I try to link it to an library (as LibCurl to use SSL connetion):
all:
g++ test.cpp -o Test -lcurl
It goes wrong (I already installed libcurl4-openssl-dev package as standard library)!
What does I miss? Can you give any solution? Thanks!!
Edit: The error is below:
fatal error: curl.h: No such file or directory
I guess, you need fix your sources:
#include <curl/curl.h>
The header files are missing in the include search path.
You will have install the development package of libcurl.
For example, install libcurl-devel-7.19.0-11.1.x86_64.rpm for Open Suse 11.1.
To know the list of files that would be installed by the rpm, download the rpm, type the following command in the downloaded dir.
rpm -qlp <rpmname>
As per the example above, the command would be
rpm -qlp libcurl-devel-7.19.0-11.1.x86_64.rpm
This will list the files along with the path in which it would be installed to.
In our example, the result would look like..
/usr/include/curl /usr/include/curl/curl.h /usr/include/curl/curlbuild.h
/usr/include/curl/curlrules.h
/usr/include/curl/curlver.h and so on...
and
Install the development libcurl package for the version of linux you use and include #include <curl/curl.h> in your code.
Refer http://curl.haxx.se/download.html to download the right one