ldconfig command reverts to previous library version - c++

I've been playing with this library for the Raspberry Pi (Raspian/DietPi - Jessie) and ran into a peculiar situation. I made some local changes, built, and installed the library like so:
cmake ..
sudo make install
sudo ldconfig
However later I made a correction to the library then built and installed the library, but did not run the 'ldconfig' command. I ran my program that uses these dynamically linked libraries and it worked with the updated libraries.
However, I then realized I forgot 'sudo ldconfig' and after executing it, the program was clearly running with the previous library version. I repeated this several times and had to actually use 'ldconfig -p' to find where the .so files were and delete them so that the next ldconfig would use the latest files, and then the problem was resolved.
Why would 'sudo ldconfig' grab a previous version of these build libraries, and where would it grab them from?

You can add your current lib path to etc/ld.so.conf and then run ldconfig again.
Or you can add to LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/new/path/newpath

Related

How to upgrade libstdc++.so on Colab runtime?

I would like to run on Colab a C++ library which requires a version of libstdc++.so which is newer than the one provided by the default g++ 7.x installed on Colab. Such requirement is due to C++17 features not supported by g++ 7.x.
In order to do so, I install a recent g++ compiler (and corresponding libstdc++.so) from a PPA. However, when I try to import libraries compiled with the updated g++ compiler it seems that the python runtime is not aware of the update to libstdc++.so, unless one restarts the runtime via "Runtime -> Restart runtime".
Since restarting the runtime is an ugly workaround, and might be disruptive for my end users, is there a better way to make the current runtime aware that libstdc++.so has changed?
I have prepared a standalone notebook which shows my problem on a simple case (using pybind11).
Thanks
To install and use recent libstdc++ do:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt install libstdc++-9-dev.
Installed include files are inside /usr/include/c++/9/ and /usr/include/x86_64-linux-gnu/c++/9/.
Installed binary library files (.a/.so) are in /usr/lib/gcc/x86_64-linux-gnu/9/.
You can list installed files of package through dpkg -L libstdc++-9-dev.
Now you can run your program like:
LD_LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/ your_program_name
So that it gets correct path and correct .so file.
Issue with your Notebook was solved for me by adding to setup.py following options, after that your Notebook doesn't print any error:
extra_compile_args=["-std=c++11", '-static', '-static-libgcc', '-static-libstdc++'],
extra_link_args=['-static-libgcc', '-static-libstdc++'],
Also you can collect all necessary .so files into folder of your Python's module and package all into wheel .whl file. There is no need to APT-install all .so dependencies on every machine. I think for Python is more clean solution to ship all necessary .so files inside .whl.

Linking problem to libraries installed with Homebrew since Mojave update

I have recently updated to Mojave and since then am experiencing linking problems to libraries (gsl, Cuba etc.) that I had installed with Homebrew.
When compiling my code, gcc (tried g++-6 and g++-8, also installed with brew) does not seem to search the directories where brew stores the header files for those libraries. The code compiled when I manually set the paths to
GSL_INCLUDE_PATH=/usr/local/include/gsl/
GSL_LIB_PATH=/usr/local/lib/
CUBA_PATH=/usr/local/include/
But since I am using this in all my make-files I do not want to do this every time...
Before I was using Sierra and I have included in my .bash_profile the following:
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
This seemed to do the trick before. But now /usr/local/sbin did not exist anymore. I ran brew doctor which suggested:
You should create these directories and change their ownership to your account.
sudo mkdir -p /usr/local/Frameworks /usr/local/sbin
sudo chown -R $(whoami) /usr/local/Frameworks /usr/local/sbin
I did just that and reinstalled the libraries but it did not sort out the issue.
I have tried to include
export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/include:/usr/local/lib:$PATH
in the bash-profile, but that did not help either. (Maybe I did it wrong, I am not familiar with setting paths) At this point I am not sure whether brew installs the libraries in a weird place or if gcc just does not look in the correct location.
I have installed Xcode and the command tools. I have tried everything I found (and could understand) that I found as solutions for related problems.
I would like for gcc to look in the directories that brew installs the libraries to by default.
I would be really grateful for a suggestion of a clean fix for this issue.
Please excuse the long essay; if you need additional information please do tell, this ist my first time asking for help here.

VisualGDB c++ to RaPi Poco no such file or directory

I am taking over a project and am pretty new with this entire setup (linux/gdb/c++). This project did work at 1 point, on RaPi 1.
Using VisualGdb to compile a c++ program to run on a RaspberryPi 2. I've seen similar questions, but either the answers didn't work or I don't fully understand how to implement.
When I try to compile, I get a fatal error: library name: No such file or directory.
2 that I know of so far are:
include "Poco/Data/Common.h"
include "Poco/Data/SQLite/Connector.h"
I have a similar program that uses different poco libraries and it compiles fine. If I look in the External Dependencies of the project, I see Common.h and Connector.h. The GDB Makefile settings have pthread PocoFoundation PocoData PocoDatad PocoDataSQLite PocoDataSQLited libraries listed.
Tried a few things, but not really sure how to debug this. I don't seem to be able to find the files on the RaPi using find -iname "Common.h", but I can't find the ones that are working in the other project either using that method.
I've done the Complete Edition install of poco and run sudo apt-get update; sudo apt-get upgrade; sudo rpi-update.
Tried to give as much info as I understand of this, but sure I missed something. Any help/suggestions would be great. Let me know if you need more info on something I didn't include.
Thanx ahead of time.
In case anyone else has this issue.
libmysqlclient-dev needs to be installed first for these libraries to get installed with the poco install.

How to add compiler include paths and linker library paths for newly installed Boost?

I have RHEL 5.2, with Boost 1.33 installed.
I downloaded boost_1_44_0.tar.bz2. and built it. On completion it showed:
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
/home/dfe/Archive/boost_1_44_0
The following directory should be added to linker library paths:
/home/dfe/Archive/boost_1_44_0/stage/lib
How do I add the above mentioned include paths?
When I do "rpm -q boost", it shows boost-1.33.1-10.el5. Why is that so, when I've installed version 1.44?
Is there a better way to install the latest version of Boost?
There are always three steps to install software on Linux systems:
configure — "check"
make — "build software in current directory"
make install — "copy files to the systems so the other software can use this software"
You likely did the equivalent of make but did not do the equivalent of make install. You need to run
sudo ./b2 install
after running ./b2
Just add the paths to your .bashrc or .profile (or whatever floats your boat) like this:
export LIBS="-L/home/dfe/Archive/boost_1_44_0/stage/lib"
export CPPFLAGS="-I/home/dfe/Archive/boost_1_44_0"
You have to include these directories into makefile which you would use to build your application
CC -I/home/dfe/Archive/boost_1_44_0 -L/home/dfe/Archive/boost_1_44_0/stage/lib yourprogram.cpp
-I option Adds dir to the list of directories that are searched for #include files.
-L option adds dir to the list of directories searched for libraries by linker
CC is sun compiler...
First, I removed the existing boost rpm using
rpm -e boost-1.33.1-10.el5
A message is displayed saying "error: "boost" specifies multiple packages"
Then tried:
rpm -e --allmatches boost
(I don't remember whether I typed 'boost' or 'boost-1.33.1-10.el5')
The packages with dependencies were shown.
I did:
rpm -e [packagename1]
rpm -e [packagename2]
and so on and then did:
rpm -e --allmatches
This erased boost completely from my system.
Then I extracted boost_1_44_0.tar.bz2 using tar -xvjf boost_1_44_0.tar.bz2 and ran bootstrap with:
./bootstrap.sh
Then ran bjam as:
./bjam install
That's it! Boost got installed on my system, and I didn't have to specify any of the linker options while compiling programs! Yay!
Now the 'rpm -q boost' command shows that there is no package installed.

Build Boost on Mac with Xcode

I've recently got acquainted with Boost library and I'd like to use it in my Xcode project. But sadly there is no HowTo or FAQ on how to do it :(
What's the sequence of actions to build and use Boost libraries in Xcode?
The easiest way I've found to do it is to install MacPorts, then you can install/build Boost via a single command:
sudo port install boost
Plus you get similar access to other open source software. The only downside I've found is that, like any other package management system, they are not always up to date with the latest version.
If you prefer Homebrew as your package manager, the command is:
brew install boost
I don't know how to use Boost from XCode (I'm not a Mac programmer), but building boost is usually done through their own build tool, bjam.
They have a guide to building boost here, and you can download the latest version of bjam here
Once it is built, you reference it from Xcode the same way you would any other library. The boost/include should be added to your include path, and the libraries in boost/lib can be referenced for the boost libs that require it.
To build boost on a mac, follow the unix variants getting started page (http://www.boost.org/doc/libs/1_39_0/more/getting_started/unix-variants.html). You won't use Xcode directly to perform the build, but once complete you can add the boost include paths and dylib's to your Xcode project.
I found that to build Boost 1.41.1 on MacOS, you need to do the following:
Download boost 1.46.1 from here: http://sourceforge.net/projects/boost/files/boost/1.46.1/
Unpack the file
Open terminal, cd to the install directory, and do the following:
chmod u+x configure.sh
cd tools/build/v2/engine/src
chmod u+x build.sh
Then go back to the install directory, and:
./configure.sh
If that runs successfully, it will tell you to run:
./bjam
That's it.. for whatever reason, I needed to set those permissions manually before it would work.
su - root
enter root password and then run below as root
/opt/local/bin/port install boost
If you have never logged in as root or forgotten your password, here are the steps to reset root password
http://support.apple.com/kb/HT1528?viewlocale=en_US&locale=en_US
For most of the boost libraries, there's nothing to build, it's all in header files.
The remainder of the instructions are here.
Currently I'm very happy with using Pete Goodliffe's script which builds a framework from the Boost source package for both iOS and Mac. Drag and drop it into a project and it works!
There are multiple versions of the script out there. Here's one:
https://gist.github.com/faithfracture/c629ae4c7168216a9856/61be257e1c0839c85743777d0687becad9913bf7
Elaboration of Ferrucio's answer:
Install Boost using MacPorts (sudo port install boost) or Homebrew (brew install boost).
Find the path to the Boost header files (it should be in /opt/homebrew/include if you're using Homebrew).
Add the path to System Header Search Paths in the Build Settings of your Xcode target.
IMPORTANT NOTE: If you add the path to User Header Search Paths instead of System Header Search Paths, as other users suggested, then your code will fail to build, since the Boost files use angled-includes (#include <boost/filename.hpp>) to include each other. Angled-includes are only for including system library headers, and thus they only work if Boost is in the System Header Search Paths.
You can read about the difference between angled-includes and quoted-includes here.