GNU ld cannot find library which is there - c++

The packages I'm toying with here are rather unknown, but nevertheless the problem is rather generic. Basically, I'm trying to compile Python module (called rql) with C++ extension. The extension uses external framework called gecode, which contains several libraries. I compiled gecode and installed locally. Now, let the output speak for itself:
red#devel:~/build/rql-0.23.3$ echo $LD_LIBRARY_PATH
/home/red/usr/lib
red#devel:~/build/rql-0.23.3$ ls $LD_LIBRARY_PATH | grep libgecodeint
libgecodeint.so
libgecodeint.so.22
libgecodeint.so.22.0
red#devel:~/build/rql-0.23.3$ python setup.py build
running build
running build.py
package init file './test/__init__.py' not found (or not a regular file)
running build_ext
building 'rql_solve' extension
g++ -pthread -shared build/temp.linux-i686-2.5/gecode-solver.o -lgecodeint -lgecodekernel -lgecodesearch -o build/lib.linux-i686-2.5/rql_solve.so
/usr/bin/ld: cannot find -lgecodeint
collect2: ld returned 1 exit status
error: command 'g++' failed with exit status 1

LD_LIBRARY_PATH is for runtime linker/loader (same effect could be achieved with ldconfig ). What you need is the -L flag:
-L/home/red/usr/lib
on the compiler command line.
Edit:
And - thanks to #bjg for reminding me - you can use LIBRARY_PATH if you don't want to mess with compiler options.

You've apparently modified LD_LIBRARY_PATH to point to a non-standard location in your home directory. Do you know if LD_LIBRARY_PATH in the environment used to call g++ in setup.py matches your shell's environment?
See if you can pass arguments to setup.py to modify the library path or simply pass -L/home/red/usr/lib to g++.

Related

R install packages looking in wrong place

Trying to install FFTW and feel like I have been going in circles. I need it for an R package (poisbinom) and I think I have it installed right (I'm on a cluster and don't have sudo privileges. I followed the instructions here: http://micro.stanford.edu/wiki/Install_FFTW3 )
The problem I'm running into is this:
g++ -std=gnu++14 -shared -L/usr/local/lib64 -o poisbinom.so RcppExports.o init.o poisbinom.o -lfftw3 -lm
/usr/bin/ld: cannot find -lfftw3
collect2: error: ld returned 1 exit status
I have a feeling it is because I did not install FFTW under usr/local/lib64, its under $HOME/usr/. My R install is under $HOME/R/lib64/R. I am not sure what variable to change to make it look in the right place, as I cant change this g++ call as it is part of an R install.packages call. I've been going in circles with this for two days now. Let me know if theres anything else I can provide to help.
I already ran install.packages("fftw") and that was successful and used LFFTW3 without issue because it looked in the right place. I mostly just need to know if I can point this gcc call to the right folder with an environment variable or something.
In case you have pkg-config on your system and your installation produced the required configuration files (e.g. fftw3.pc): Define the environment variable PKG_CONFIG_PATH to (also) include the directory with these configuration files for FFTW3.
Otherwise, you can define FFTW_CFLAGS and FFTW_LIBS:
fftw$ ./configure --help
[...]
FFTW_CFLAGS C compiler flags for FFTW, overriding pkg-config
FFTW_LIBS linker flags for FFTW, overriding pkg-config
[...]
I ended up having to add the variables to my bashrc file:
export PATH=$HOME/fftw_folder/bin:$PATH
export LD_LIBRARY_PATH=$HOME/fftw_folder/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=$HOME/fftw_folder/lib:$LIBRARY_PATH
export PKG_CONFIG_PATH=$HOME/_folder/lib/pkgconfig:$PKG_CONFIG_PATH
As laid out here: http://hpc.loni.org/docs/faq/installation-details.php
And now things seem to be moving forward smoothly. Thanks for the help!

c++ Makefile doesn't find library

i want to run a "make" command in linux terminal in order to use some c++ libs.
Unluckily while running the "make" an error appears saying it cannot find the requested libs.
Here the relevant makefiles:
Here are the files in my filesystem which should be linked.
Why does makefile not find the libraries ?
Thanks for all answers in advance
Try to modify your Makefile for -lgmp rather than -libgmp
In background the compiler adds the 'lib' onto the name as well as the extension .so and similar stuff.
Try running the following to get an overview of what the linker is trying to do:
ld -L [yourincludepath] -lgmp --verbose
Such resolution issues might be due to the fact you are trying to link a 64bit library with a 32bit application? Try installing a proper XX-bits of the lib maybe?
Try to add -m option (machine dependency):
ld -melf_i386 -L /usr/lib/i386-linux-gnu/ -lgmp --verbose
Other values which might be supported on your side:
elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu i386linux elf_l1om elf_k1om i386pep i386pe
More info:
usr/bin/ld: cannot find -l<nameOfTheLibrary>

Linking Paho C Mqtt library error in C++ Project

I'm trying to include the MQTT-C-Client-Library in a simple C++ project.
I have included the header file succesfully like this #include "MQTTClient.h". Compiling it in the linux terminal was printing this errors:
[xy#localhost mosquittoProject]$ sudo g++ *.cpp -o MQTTTest
/tmp/ccHn3s6m.o: In function `main':
mosquitto_test.cpp:(.text+0x11e): undefined reference to `MQTTClient_create'
mosquitto_test.cpp:(.text+0x13f): undefined reference to `MQTTClient_connect'
collect2: error: ld returned 1 exit status
I figured out that I need to link the library after some googling: Example MQTT Client Code not working C
Based on this question and answer I tried compiling it again like this:
sudo g++ -L/home/xy/Desktop/paho.mqtt.c/build/output/ *.cpp -l paho-mqtt3c -o MQTTTest
Which compiles fine but when running I get still an error.
Console commands and output:
[xy#localhost mosquittoProject]$ sudo g++ -L/home/xy/Desktop/paho.mqtt.c/build/output/ *.cpp -l paho-mqtt3c -o MQTTTest
[xy#localhost mosquittoProject]$ ./MQTTTest
./MQTTTest: error while loading shared libraries: libpaho-mqtt3c.so.1: cannot open shared object file: No such file or directory
I replaced the actual username by xy in this post.
What am I doing wrong here?
The problem looks like the library (libpaho-mqtt3c.so.1) is not on the library path.
It looks like you are linking against the build location of the library and have not installed it to the default system location (e.g. /usr/local/lib) by running sudo make install.
By default on Linux the runtime linker searches the locations listed in /etc/ld.so.conf and /etc/ld.so.conf.d. if you edit these remember to run sudo ldconfig to update the cache.
You can add the location of the library to the LD_LIBRARY_PATH environment variable e.g.:
$ LD_LIBRARY_PATH=/home/xy/Desktop/paho.mqtt.c/build/output/ ./MQTTTest

Clang linker does not look into LD_LIBRARY_PATH

I am trying to build and link a C++, cmake-based project with clang (3.0). This project links to several libraries that are installed in a custom directory /my/dir/. This directory is included in the LD_LIBRARY_PATH and LIBRARY_PATH environment variables. Project builds and links fine with g++.
The link command generated and executed by cmake looks like the following:
/usr/bin/clang++ -O3 stuff.cpp.o -o stuff -rdynamic -lmylib
ld then complains with the following message:
/usr/bin/ld: cannot find -lmylib
The link command above runs fine whenever I manually add -L/my/dir/. Is there a way to link without specifying the -L flag?
The $LD_LIBRARY_PATH environment variable (and its various alternatives on other UNIX-based platforms) is used at runtime, not link time, to find libraries.
Using -L is the correct approach and cannot be avoided.
Note: A better approach under Linux (you don't specify your platform so I'm guessing) is to correctly configure a file in /etc/ld.so.conf.d/ and avoid using $LD_LIBRARY_PATH altogether.

/usr/bin/ld: cannot find -llibeststring.a

I am using festival TTS c++ API in my program.I have downloaded all files from http://www.cstr.ed.ac.uk/downloads/festival/2.0.95/
and install festival and speech_tools successfully on my UBUNTU 10.04
now when compile my c++ programme gcc gives error:
g++ -L/usr/lib -L/home/peeyush/Desktop/festival/src/lib -L/home/peeyush/Desktop/speech_tools/lib -o"peeyush" ./src/peeyush.o -llibeststring.a -llibestbase.a -llibestools.a -llibFestival.a
/usr/bin/ld: cannot find -llibeststring.a
collect2: ld returned 1 exit status
make: *** [peeyush] Error 1
so please help me to sort out this error.
-Thanks
Peeyush Chandel(INDIA)
When using the -l option, you don't specify the leading lib or trailing .a or .so parts of the name as they're assumed by the linker. You would want to use something like -leststring to pick it up (assuming that your -L path is set correctly.
Alternately you can specify the exact filename (so no -l, just libeststring.a) as part of the object list to link (make sure the order is right relative to your .o files), but I believe in that case you would have to specify the path as the linker won't know to search your -L path. Easiest is to use -l though.