I am making use of a logging library, named liblogger, (that I've implemented) within another library, libmsg. For both of them, I'm using the autotools. I successfully install the liblogger library in my system, under the /usr/local/lib directory.
Within the configure.ac script of the other libmsg, I verify that liblogger is installed in the system, as follows:
AC_CHECK_LIB([logger],
[log_init],
[],
[
echo "Error: Could not find liblogger."
exit 1
])
And add the "-L/usr/local/lib" path to the LDFLAGS variable.
The AC_CHECK_LIB test finds the library, and both the libmsg library and its check_PROGRAMS using are successfully compiled.
However, when I try to execute the test programs, I get the error:
error while loading shared libraries: liblogger.so.0: cannot open shared object file: No such file or directory
Indeed, ldd does not find the library either:
$ ldd msgs
linux-vdso.so.1 => (0x00007fff543ff000)
liblogger.so.0 => not found
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fdf329ad000)
But the library is actually there, in /usr/local/lib.
For linking the test program, libtool is being called with the instruction:
$ /bin/bash ../libtool --tag=CC --mode=link gcc -I../include -I../msg -L/usr/local/lib -O2 -Wall -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/local/include -I/usr/local/lib -L/usr/local/lib -o msgs msgs.o message.o base64.o misc.o -llogger -lglib-2.0
Which actually echoes the following:
libtool: link: gcc -I../include -I../msg -O2 -Wall -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/local/include -I/usr/local/lib -o msgs msgs.o message.o base64.o misc.o -L/usr/local/lib /usr/local/lib/liblogger.so -lglib-2.0
So, the -llogger flag is being substituted by -L[..] /usr/local/liblogger.so (I suppose this is a correct behavior? I haven't been able yet to determine it...)
Actually, if I call the test program with:
LDPRELOAD=/usr/local/lib/liblogger.so msgs
It actually works.
Can anyone tell me what is it what I'm missing?
You need to check if:
/usr/local/lib is in /etc/ld.so.conf (it usually is these days).
ldconfig was run when you installed liblogger. If not, run it.
liblogger.so.0 is actually in /usr/local/lib.
Related
I am trying to cross-compile Dropbear for an x86 machine where glibc is missing and instead, uclibc is being used. For that aim, I have cross-compiled zlib for this same instruction set using a custom crosstool-ng toolchain and installed it to a custom location.
msainz#ubuntu:~$ ls Projects/zlib_install/lib
libz.a libz.so libz.so.1 libz.so.1.2.11 pkgconfig
I have copied Projects/zlib_install/include/zlib.h and Projects/zlib/include/zconf.h to Projects/dropbear/zlibincludes/.
I've set my env variables this way:
msainz#ubuntu:~$ echo $PATH
usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:
/usr/local/games:/snap/bin:/home/msainz/x-tools/x86_64-multilib-linux-uclibc/bin
msainz#ubuntu:~/Projects/dropbear$ echo $LDFLAGS
/home/msainz/Projects/zlib_install/lib/libz.a
msainz#ubuntu:~/Projects/dropbear$ echo $CFLAGS
-Izlibincludes -I../zlibincludes
I launch the configure script this way: ./configure --prefix=/home/msainz/Projects/tmp_top_dir --host=x86
The execution terminates with the following error:
configure:4851: x86_64-multilib-linux-uclibc-gcc -o conftest -Izlibincludes -I../zlibincludes -Wno-
pointer-sign -fno-strict-overflow -fPIE -fstack-protector-strong -D_FORTIFY_SOURCE=2 -mfunction-
return=thunk -mindirect-branch=thunk /home/msainz/Projects/zlib_install/lib/libz.a -pie -Wl,-z,now -
Wl,-z,relro conftest.c -lz >&5
/home/msainz/x-tools/x86_64-multilib-linux-uclibc/bin/../lib/gcc/x86_64-multilib-linux-
uclibc/8.3.0/../../../../x86_64-multilib-linux-uclibc/bin/ld.bfd: cannot find -lz
collect2: error: ld returned 1 exit status
Any ideas to solve this? Thanks in advance.
Solved the problem adding --with-zlib=/home/msainz/Projects/zlib_install/ to the ./configure call.
I really want to know where does this libgdbm comes from and it seems it has been in
/usr/lib/libgdbm.so.2.0.0
/usr/local/lib/libgdbm.a
/usr/local/lib/libgdbm.la
/usr/local/lib/libgdbm.so
/usr/local/lib/libgdbm.so.3
/usr/local/lib/libgdbm.so.3.0.0
, but perl says
I used the command:
cc -o try -O2 -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -fstack-protector -L/usr/local/lib try.c -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
./try
and I got the following output:
./try: error while loading shared libraries: libgdbm.so.4: cannot open shared object file: No such file or directory
The program compiled OK, but exited with status 127.
(The supplied flags or libraries might be incorrect.)
You have a problem. Shall I abort Configure [y]
Ok. Stopping Configure.
so many files, I don't know why perl can't find any of them.
Try adding "-R/usr/local/lib" to LDFLAGS and/or CFLAGS environment variables.
If Linux perhaps change the order of searched directories in /etc/ld.so.conf
I have an error making a code project because of what I believe is a missing routine from lapack:
HomographyInit.cc:(.text+0x385): undefined reference to `dgesvd_'
I think I need to add lapack library somehow to my Makefile. Here is part of my Makefile:
CC = g++
COMPILEFLAGS = -I MY_CUSTOM_INCLUDE_PATH -D_LINUX -D_REENTRANT -Wall -O3 -march=nocona -msse3
LINKFLAGS = -L MY_CUSTOM_LINK_PATH -lGVars3 -lcvd
I tried doing the following to no avail:
CC = g++
COMPILEFLAGS = -I MY_CUSTOM_INCLUDE_PATH -D_LINUX -D_REENTRANT -Wall -O3 -march=nocona -msse3
LINKFLAGS = -L MY_CUSTOM_LINK_PATH -lGVars3 -lcvd **-llapack**
Result:
make
...
/usr/bin/ld: cannot find -llapack
collect2: ld returned 1 exit status
How can I add lapack to my project? I am pretty sure I installed it correctly, though would be willing to double-check that somehow.
It looks like liblapack isn't in the path that ld can find. I would suggest two things:
Establish a symbolic link manually. It is possible (and sometimes common) that ld cannot recognize liblapack.so.3gf or liblapack.so.3.0.1 or so are essentially liblapack.so. You can set up a link by ln -s liblapack.so.3gf liblapack.so
Install liblapack-dev package instead if you're using ubuntu or debian repos. For some unclear reasons, liblapack3gf is not the same as liblapack-dev. I am not sure if in any circumstances, both will do or not do the same thing.
I think the first item should be able to resolve your problem (hopefully).
On my computer the dynamic library is in /usr/lib64/liblapack.so.3.4.1 and contains the requested symbol:
$ nm -D /usr/lib64/liblapack.so.3.4.1 | grep dgesvd
0000000000189200 T dgesvd_
So I would guess that the place where your lapack is installed is not in the linker search path. You should add the flag -L/path/to/the/lapackdir to LINKFLAGS
I am learning to create shared libraries in Linux, subsequently to develop parallelised scientific computing programs. I took the toy example from here for shared library. I modified the Makefile from this question to suit the toy example. My Makefile now is
CC = mpicc
INCDIR = -I ./
CFLAGS = -Wall -rdynamic -g -fPIC $(INCDIR)
LIBADD = -L ./ -lcalc_mean
all: dyn_main.out
dyn_main.out: libcalc_mean.so
$(CC) -o $# main.c $(LIBADD)
libcalc_mean.so: calc_mean.o
$(CC) -shared --export-dynamic -o $# $<
calc_mean.o: calc_mean.c
$(CC) $(CFLAGS) -c $<
clean :
-rm *.o
-rm *.out
-rm *.so
.PHONY:
clean
When I make with CC = gcc in the Makefile, things run fine. I could run the binary even with mpirun.
When I have CC = mpicc in the Makefile, I get the following error.
mpicc -Wall -rdynamic -g -fPIC -I ./ -c calc_mean.c
mpicc -shared --export-dynamic -o libcalc_mean.so calc_mean.o
mpicc -o dyn_main.out main.c -L ./ -lcalc_mean
/home/elan/localinstalls/lib/libmpi.so: undefined reference to `pthread_key_create'
/home/elan/localinstalls/lib/libmpi.so: undefined reference to `pthread_getspecific'
/home/elan/localinstalls/lib/libmpi.so: undefined reference to `pthread_create'
/home/elan/localinstalls/lib/libmpi.so: undefined reference to `pthread_atfork'
/home/elan/localinstalls/lib/libmpi.so: undefined reference to `pthread_setspecific'
/home/elan/localinstalls/lib/libmpi.so: undefined reference to `pthread_join'
collect2: ld returned 1 exit status
make: *** [dyn_main.out] Error 1
I added the path to libpthread.so,.a to LD_LIBRARY_PATH, but no avail. I have a self compiled openmpi-1.5.4. If this were a openmpi dependency, shouldn't it have been resolved when I configured it?
Is this error familiar? I am using Ubuntu 11.04, with gcc 4.5.2. I already built and run some mpi parallel programs successfully. But they are large packages configured with autotools. One of the config.log s display the same error. But even that one runs fine.
References to / examples of creating static/shared libraries with mpi will also be appreciated (though Openmpi discourages fully static libraries.)
Thank you very much,
Elan.
You should be able to just add -lpthread.
Open MPI probably didn't add it because it found that adding -lpthread wasn't necessary (likely due to some other dependency implicitly pulling in the pthread library). But with the linker flags you're using, you might well have changed that implicit dependency, so the pthread library isn't being pulled in automatically anymore.
If adding -lpthread to the command line fixes the issue, then see this FAQ entry for how to update the wrapper compilers (E.g., add your own flags): http://www.open-mpi.org/faq/?category=mpi-apps#override-wrappers-after-v1.0
You can see what options the Open MPI compiler wrapper supplies to the underlying compiler and linker using the -showme option or one of its specific variants:
-showme:compile to just show the compiler flags
-showme:link to just show the linker flags
For example:
$ mpicc -showme
icc -I/opt/MPI/openmpi-1.5.3/linux/intel/include -I/opt/MPI/openmpi-1.5.3/linux/intel/include/openmpi -fexceptions -pthread -I/opt/MPI/openmpi-1.5.3/linux/intel/lib -Wl,-rpath,/opt/MPI/openmpi-1.5.3/linux/intel/lib -I/opt/MPI/openmpi-1.5.3/linux/intel/lib -L/opt/MPI/openmpi-1.5.3/linux/intel/lib -lmpi -ldl -Wl,--export-dynamic -lnsl -lutil
Ok, I've added some functionality to a linux library.
However even after 'make install' the program I'm trying to confirm functionality is linking to the previous version.
So 'make install' puts my libraries here:
'/usr/local/lib'
and
'/usr/local/include'
I used the following on configure:
./configure --enable-maintainer-mode --enable-uninstalled-build 'CFLAGS=-g -O0' 'CXXFLAGS=-g -O0' 'JFLAGS=-g -O0' 'FFLAGS=-g -O0' CPPFLAGS='-L /usr/local/lib/ -I /usr/local/include/gpod-1.0/'
But when I try to execute the program I get 'Symbol not found' and 'Plugin can not load'
When I ldd the produced plugin so:
~/Development/rhythmbox/plugins/ipod/.libs$ ldd libipod.so
linux-gate.so.1 => (0x00d97000)
librhythmbox-core.so.1 => /home/gary/Development/rhythmbox/shell/.libs/librhythmbox core.so.1 (0x009ad000)
libgpod.so.4 => /usr/lib/libgpod.so.4 (0x00509000)
The emphasis being stressed because it's obviously linking to the wrong library... When I look in the make file I see the following:
IPOD_CFLAGS = -pthread -I/usr/local/include/gpod-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12
IPOD_LIBS = -pthread -L/usr/local/lib -lgpod -lgdk_pixbuf-2.0 -lm -lgobject-2.0 -lgmodule-2.0 -lpng12 -lgthread-2.0 -lrt -lglib-2.0
So the CPPFLAGS are being passed through to the plugin, and in .deps I see the proper header file being included... IE:
~/Development/rhythmbox/plugins/ipod/.deps$ less rb-ipod-source.Po | grep gpod
/usr/local/include/gpod-1.0/gpod/itdb.h ../../lib/eel-gconf-extensions.h
/usr/local/include/gpod-1.0/gpod/itdb.h:
Ubuntu 10.10
Any ideas?
You need to set LD_RUN_PATH to /usr/local/lib before running configure and make. This will embed /usr/local/lib as a shared library search path into the executable.
libgpod.so is pointing to the old version of the library.