Including and using libraries with autotools - c++

I am an autotools newbie; I'm doing an application that needs to parse xml files, using xerces-c 3.1.
My code works fine when I install the xerces-c library with the apt-get utility (then xerces-c libraries and include files are installed in /usr/lib and /usr/include/xercesc, respectively). In my configure.ac file I have the following macro:
AC_CHECK_LIB([xerces-c],[main],[],[AC_MSG_ERROR([*** xerces-c lib not found])])
OK, as I said, this works as expected. However, I want to have the libraries inside the project directory (to be included in the distribution package), and here my problems begin.
I uninstall the xerces-c libraries, and I copy the xerces-c libraries (downloaded from the xerces-c webpage) to my project directory. Then, I add the to my confgure.ac the macro:
LDFLAGS="$LDFLAGS -L/home/xxxx/workspace/P3/src/lib"
Finally, I generate the makefiles and compile, just executing the following commands in the project root directory:
autoconf
automake
./configure
make
The compilation looks good, and the linking looks fine too:
g++ -g -O2 -L/home/xxxx/workspace/P3/src/lib -o app app-P3.o -lxerces-c
But when I execute the application I got an error like:
./src/app: error while loading shared libraries: libxerces-c-3.1.so: cannot open shared object file: No such file or directory
What I'm doing wrong?
Thanks in advance.

Since you are using a shared library libxerces-c-3.1.so needs to be somewhere where it can be found by ld. In the previous case where you installed the xerces-c package, libxerces was installed in /usr/lib or somewhere where it could be found. You can probably get it working for now by:
LD_LIBRARY_PATH=$PATH:/home/xxxx/workspace/P3/src/lib ./src/app
but this is something that you'll have to figure out eventually for your package install.

Related

How to link fftw3 on a macOS using CMake?

I have the following fftw3 header files under /usr/local/include:
Further, I have the following fftw3 static libraries under /usr/local/lib:
However, when I try to compile my file using cmake and running make afterwards, I get the following errors:
What I find particularly odd is that when compiling the individual *.cpp files, I get no error despite the fact that these files use fftw_malloc and other functionality from fftw3.h.
I'm using gcc and g++ version 10.2.0. I configure my CMake file using cmake -DCMAKE_CXX_COMPILER=g++-10 -DCMAKE_C_COMPILER=gcc-10.
I configured fftw3 through the download on the fftw3 website and running ./configure, make, sudo make install in that order. As mentioned before, the files seem to have been installed in the correct place. I also tried the same with homebrew and MacPorts and ended up with the same result.
I'm also using findFFTW. Without this, even the *.cpp files don't seem to compile properly. Further, even findFFTW claims to have found the FFTW3 library, giving the following output during the configuration of the make file:
-- Found FFTW: /usr/local/include
Finally, my target link libraries are set to the following in the CMake file:
target_link_libraries(cartogram CGAL::CGAL Boost::program_options fftw3)
Is there any way I can solve the error I get? (ld: library not found for -lfftw3)
Edit: On a side note, the exact same cmake file works perfectly find on Ubuntu, Linux!

How do I install OpenXLSX on Linux?

I want to use this library https://github.com/troldal/OpenXLSX on my linux machine. How do I install or use libraries found on Gitub?
Also how do I know what compiler flags to use?
The library you linked to is built using CMake (can be seen by the existence of a CMakeLists.txt file).
So you'd have to
download the source code (git clone https://github.com/troldal/OpenXLSX.git on Linux/Mac or using git bash on Windows)
generate the build system for your compiler (mkdir build; cd build; cmake .. on Linux/Mac)
build the library (make on Linux/Mac)
Once you have built the library, generally there is an include directory and a lib directory (sometimes also named bin). If you are compiling directly using g++ or clang++, you'll have to add the include directory with the -I flag and the built library file in lib or bin with the -l flag:
g++ -Ipath/to/include -l/path/to/lib/libOpenXLSX.so your_sources.cpp
If you are using CMake or an IDE with its own build system, you'll have to add those two paths according to the documentation of that build system (see target_link_libraries for CMake for example).
CMake sometimes also generates "install" commands for built library. When you install the libraries, the headers and library will be copied to your global include path, so you won't need to specify the paths in your compile command anymore: g++ -lOpenXLSX your_sources.cpp.
Use the git clone command to download the library these two questions already answered would probably help you the most:
And in regards to flags you would use the -I flag.
How to use Libraries
C++ Link external libraries

wxWidgets jpeg library build issue

I'm trying to build wxWidgets library into a custom path on a Fedora 27 operative system.
I achieved the wx-config file path recognition and works with the cmake execution. Also, I load libraries and include dirs based on modified wxWidgets finder cmake file that sets thewx-config custom path successfully.
But cmake does not load my wxWidgets configuration. I mean, wx_gtk2u_jpeg-3.1 builded lib could not be founded (suposed to be /usr/lib/libwx_gtk2u_jpeg-3.1.so). I need jpeg dependency from wxWidgets for my project.
I'm sure that problem is not about cmake files. However, the problem is wxWidgets compilation because cmake can found the other builded dependencies into /usr/lib/
I actually installed the libjpeg-turbo-devel package that includes the libjpeg.h needed for wxWidgets building without success of libwx_gtk2u_jpeg-3.1.so creation.
The weirdest part is that $ wx-config --libs shows the wx_gtk2u_jpeg-3.1 lib to be linked and the hint paths that it should be founded.
wxWidgets commands for building:
$ ./configure --with-libjpeg=builtin --with-libpng=builtin --with-libtiff=builtin --with-zlib=builtin --with-expat=builtin --enable-webviewwebkit=no --prefix=/opt/cpp_dependencies/2018Q1/usr'
$ make -j 4
$ make install
You can check out my cmake files, the cmake output and wxWidgets building output in order to reproducing it: https://gist.github.com/jjalvarezl/b70accae269ef56c56010bedf157c27f
You can see line 1543 of wxWidgets building output file that jpeg library is buildin, and, 1564 of same file, the make install command that installs all libwx_<lib_name>.so libraries into final /usr/lib path. Anyway, no one contains the needed library.
Please show the exact error message, as it's not clear what the actual problem is. What I can say, is that the different built-in versions of 3rd party libraries, such as libjpeg, are always static libraries, even when wxWidgets themselves are shared. I.e. you're never going to have libwx_gtk2u_jpeg-3.1.so, only .a.
I'd also strongly recommend using system versions of the 3rd party libraries under Unix systems. This means that your wxWidgets applications will get security updates from your OS vendor and you don't risk running into any incompatibilities due to using 2 different versions of the same library in your application.

libtorrent-rasterbar7: g++ linker unable to find libtorrent/session.hpp

When compiling the libtorrent tutorial 'hello world' with:
g++ main.cpp -o run -ltorrent-rasterbar -lboost_filesystem-mt -L /usr/lib/
=> fatal error: libtorrent/session.hpp: No such file or directory
Despite having libtorrent-rasterbar7 installed (both libtorrent-rasterbar.so.7 and libtorrent-rasterbar.so.7.0.0 exist in /usr/lib/). Also I'm able to run a simple python script that imports and uses libtorrent without issues.
The g++ command I'm using is identical to the solution for a similar issue with version 6 yet still having the error.
You haven't installed the libtorrent-rasterbar header files. The
package you are missing is the libtorrent-rasterbar development
package. What it is called depends on your distro. (On Debian or Ubuntu
it is libtorrent-rasterbar-dev. On Fedora it is libtorrent-rasterbar-devel).
Whenever you want to write an application that links with a packaged library
you need to install not simply the runtime library but the associated development
package, which provides both the runtime library and its header files.
BTW, there is no need to pass -L /usr/lib to the linker as /usr/lib is one of the default linker search directories.

Importing Armadillo C++ library into Xcode

I'm a mac user and am trying to install and import C++ Armadillo library. Here are the steps I've had so far:
1) I downloaded the Armadillo library from its website.
2) I went over the Readme.txt file in the download file explaining how to install it.
3) I used CMake to make the armadillo download files into binary files.
4) Then by using terminal and the code sudo make install, I installed the binary codes and they generated some "library-like" files: libarmadillo.4.0.2.dylib, libarmadillo.4.dylib, lib armadillo.dylib
5) I then copied all these files into /url/lib directory.
6) Now I have my Xcode program running and I'm trying to include the armadillo library via the include command. The problem is Xcode highlights this line and it says "armadillo file not found". Could anyone please help me solve this issue?
Thanks very much,
You need to set the following things in your build settings:
Header Search Paths: /path/to/armadillo/include (e.g. something like /url/lib/armadillo/include)
This is all you need for your source to compile. However, in order to get your program to link, you will also need the following:
Library Search Paths: /path/to/armadillo/libraries (e.g. something like /url/lib/armadillo/lib)
Other Linker Flags: -larmadillo (or: add the armadillo library to your Link build phase using the GUI)
If you're not exactly sure how to properly build and install armadillo (e.g. which prefix to use when configuring), I highly recommend using a package manager such as MacPorts to do it for you,
Install port from here
run the following command:
sudo port install armadillo
Your header path and library path will be: /opt/local/include and /opt/local/lib respectively