Linux: C++: /usr/bin/ld: cannot find -llibboost_serialization - c++

When I try to build some application with linking boost's library libboost_serialization.so, I have this error message:
/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/bin/ld: cannot find -llibboost_serialization
collect2: ld returned 1 exit status
This is the output from ldconfig:
linux-rxa13:/usr/lib64 # ldconfig -p | grep serialization
libboost_wserialization.so.1.46.1 (libc6,x86-64) => /usr/lib64/libboost_wserialization.so.1.46.1
libboost_wserialization.so (libc6,x86-64) => /usr/lib64/libboost_wserialization.so
libboost_serialization.so.1.46.1 (libc6,x86-64) => /usr/lib64/libboost_serialization.so.1.46.1
libboost_serialization.so (libc6,x86-64) => /usr/lib64/libboost_serialization.so
And this is command line to build test application:
g++ -o "m" m.o -L/usr/lib64 -llibboost_serialization
I've searched for the solution to this problem, but I haven't found it. Thanks!

Don't put in the lib: -lboost_serialization

I removed the "lib" from -llibboost_serialization and that worked for me. So it ended up being:
-lboost_serialization

Related

Linker can't find mathgl library

I try to make mathgl work, but the linker can't find the library. I installed it through the user repository from arch linux.
I just copied the example program:
#include <mgl2/mgl.h>
int main()
{
mglGraph gr;
gr.FPlot("sin(pi*x)");
gr.WriteFrame("test.png");
}
The official website states you need to link lmgl, but I get this error:
$ g++ main.cpp -lmgl
/usr/bin/ld: cannot find -lmgl
collect2: error: ld returned 1 exit status
I couldn't figure out where to start looking for the library. How can I see where it was installed?
I was looking for libmgl with ldconfig -p getting these results:
$ ldconfig -p | grep libmgl
libmgl2.so.7.5.0 (libc6,x86-64) => /usr/lib/libmgl2.so.7.5.0
libmgl2.so (libc6,x86-64) => /usr/lib/libmgl2.so
libmgl2-qt5.so.7.5.0 (libc6,x86-64) => /usr/lib/libmgl2-qt5.so.7.5.0
libmgl2-qt5.so (libc6,x86-64) => /usr/lib/libmgl2-qt5.so
libmgl2-qt.so.7.5.0 (libc6,x86-64) => /usr/lib/libmgl2-qt.so.7.5.0
libmgl2-qt.so (libc6,x86-64) => /usr/lib/libmgl2-qt.so
libmgl2-glut.so.7.5.0 (libc6,x86-64) => /usr/lib/libmgl2-glut.so.7.5.0
libmgl2-glut.so (libc6,x86-64) => /usr/lib/libmgl2-glut.so
As Amadeus indicated, using
$ g++ main.cpp -lmgl2
should work.

Compiling OpenGL Program (Linux) - Cannot find -lGL

I am attempting to compile a test opengl program on ubuntu. I have installed bumblebee, the nvidia 304 driver and libgl1-mesa-dev, using apt-get.
I can see the file /usr/lib/libGL.so.1 - and yet compiling with g++ and the flag -lGL returns the error: error: cannot find -lGL.
Any ideas on what I can do to fix this?
Output of dpkg -L libgl1-mesa-dev
/.
/usr
/usr/share
/usr/share/bug
/usr/share/bug/libgl1-mesa-dev
/usr/share/bug/libgl1-mesa-dev/script
/usr/share/bug/libgl1-mesa-dev/control
/usr/share/doc
/usr/share/doc/libgl1-mesa-dev
/usr/share/doc/libgl1-mesa-dev/copyright
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/mesa
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/gl.pc
/usr/share/doc/libgl1-mesa-dev/changelog.Debian.gz
/usr/lib/x86_64-linux-gnu/mesa/libGL.so
/usr/lib/x86_64-linux-gnu/libGL.so
/usr/lib/x86_64-linux-gnu/libglapi.so
Update
The command ldconfig -p | grep libGL.so gives the output:
libGL.so.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libGL.so.1
libGL.so.1 (libc6,x86-64) => /usr/lib/libGL.so.1
libGL.so.1 (libc6) => /usr/lib/i386-linux-gnu/libGL.so.1
libGL.so (libc6) => /usr/lib/i386-linux-gnu/libGL.so
I don't know if that's useful or correct?

Build Virtuoso (with Mono integration) on Ubuntu: build error on libgc

UPDATE: Okay, I found it on this page: you have to run ./configure with the --enable-mono parameter. Then you'll also find out that some more dependencies are missing that aren't mentioned anywhere.
Sadly, this leaves me with another problem I cannot solve. As we still have the unfinished bounty here, let's ask this.
After doing ./autogen and ./configure --enable_mono (tried it on the code branches develop/6 and develop/7), I get the following error:
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../libsrc/Dk -fno-strict-aliasing -O2 -DMONO_USE_EXC_TABLES -fexceptions -D_REENTRANT -D_GNU_SOURCE -Wall -DNDEBUG -DPOINTER_64 -I/usr/local/src/virtuoso-opensource/libsrc/Xml.new -DOPENSSL_NO_KRB5 -Dlinux -D_GNU_SOURCE -DFILE64 -D_LARGEFILE64_SOURCE -I../../binsrc/mono/mono-1.1.7/libgc/include -I../../libsrc -I../../libsrc/Dk -DNO_UDBC_SDK -DUSE_INCLUDED_LIBGC=1 -g -O2 -MT libthrp_gc_la-sched_pthread_gc.lo -MD -MP -MF .deps/libthrp_gc_la-sched_pthread_gc.Tpo -c sched_pthread_gc.c -fPIC -DPIC -o .libs/libthrp_gc_la-sched_pthread_gc.o
sched_pthread_gc.c:42:22: fatal error: gc_typed.h: No such file or directory
compilation terminated.
make[2]: *** [libthrp_gc_la-sched_pthread_gc.lo] Error 1
make[2]: Leaving directory `/usr/local/src/virtuoso-opensource/libsrc/Thread'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/virtuoso-opensource/libsrc'
make: *** [all-recursive] Error 1
This link has the contents of the problematic file. If I remove the import for gc_typed.h, the next import is not found. I just did sudo apt-get install libgc-dev which worked. Make still gives me the same error. I believe somewhere around this file and this compilation the error is buried, but I can't fix it.
I'm a Linux noob, can somebody give me advice what might be the problem here or how to solve it?
Additional Information:
1. ldconfig -v -p clearly says that libgc.so exists, so why is this make script looking for the header?
...
libgdbm_compat.so.3 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libgdbm_compat.so.3
libgdbm.so.3 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libgdbm.so.3
libgd.so.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libgd.so.2
libgcrypt.so.11 (libc6,x86-64) => /lib/x86_64-linux-gnu/libgcrypt.so.11
libgccpp.so.1 (libc6,x86-64) => /usr/lib/libgccpp.so.1
libgccpp.so (libc6,x86-64) => /usr/lib/libgccpp.so
libgcc_s.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libgcc_s.so.1
libgc.so.1 (libc6,x86-64) => /usr/lib/libgc.so.1
libgc.so (libc6,x86-64) => /usr/lib/libgc.so
libgamin-1.so.0 (libc6,x86-64) => /usr/lib/libgamin-1.so.0
libgailutil.so.18 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libgailutil.so.18
libfuse.so.2 (libc6,x86-64) => /lib/libfuse.so.2
...
To install Virtuoso with Mono support, I used the following tutorials:
the README on the Virtuoso GitHub page
I had small problems doing the exports on this Mono-Virtuoso page, might one of those be the problem?
Virtuoso has been working before, I just don't get Virtuoso to build with --enable-mono. Mono works well, can build and execute dlls and exes without a problem.
.
.
.
ORIGINAL QUESTION:
I installed Virtuoso and Mono on a Ubuntu server and using this
tutorial compiled the sanity.cs class to a sanity.dll file. When I
tried importing the 'vector' I got a message:
SQLState: 42001
Message: SR185: Undefined procedure DB.DBA.import_clr.
Does that mean that I put the .dll in the wrong place? Or do I have
the wrong version of Virtuoso installed?
I used apt-get to install Virtuoso and Mono.
UPDATE: Okay, the apt-get version of Virtuoso was waaay too old. The
OpenLink Twitter account told me that the new versions should be built
from the Github account.
Now I built Virtuoso on Ubuntu following the readme on
https://github.com/openlink/virtuoso-opensource, but that doesn't
explain how to integrate Mono in any way.
I already made the sanity.cs Hello World file work, confirming that Mono is setup correctly.
The server runs, but the Mono section in the Virtuoso.ini is empty:
.
[Mono]
;MONO_TRACE = Off
;MONO_PATH = <path_here>
;MONO_ROOT = <path_here>
;MONO_CFG_DIR = <path_here>
;virtclr.dll =
I put the default paths in this file like this:
[Mono]
;MONO_TRACE = Off
;MONO_PATH = /usr/bin/mono
;MONO_ROOT = /usr/lib/mono
;MONO_CFG_DIR = /etc/mono
;virtclr.dll =
I cannot find a virtclr.dll on my system. How can I generate it? Can
someone help me with a link explaining how to integrate Mono in
Virtuoso or tell me how to proceed? Should I have built Virtuoso with
different settings?
It's a bit of a mess. It depends on mono-1.1.7, and it doesn't build it before trying to use items that it depends on; so the build is messy. I would strongly suspect that the developers are not building/testing this aspect of their project.
You need to download mono-1.1.7 manually - this is because the location of the mono tarball is not where they think it is.; e.g. from:
wget -O binsrc/mono/mono-1.1.7.tar.gz ftp://ftp1.freebsd.org/mirror/FreeBSD-Archive/ports/distfiles/mono-1.1.7.tar.gz
if you don't have wget, then you can use curl:
curl -o binsrc/mono/mono-1.1.7.tar.gz ftp://ftp1.freebsd.org/mirror/FreeBSD-Archive/ports/distfiles/mono-1.1.7.tar.gz
run configure:
./configure --enable-mono
Swap the order of the binsrc and libsrc subdirectories in the Makefile:
sed -i 's/libsrc binsrc/binsrc libsrc/' Makefile
run make (use a -j option if you want to make it faster e.g. -j2):
make
The build will fail. Do not panic. Swap binsrc and libsrc again:
sed -i 's/binsrc libsrc/libsrc binsrc/' Makefile
and re-run make:
make
The build should succeed at this point.
Bear in mind, it uses a private copy of mono-1.1.7, and most modern linux distros use 2.0, so there could be some conflicts with this.

Shared library, makefile. Library path

Im trying to link my program to the shared library. Im using a makefile to compile. It looks like this: `
make: sms_out.cpp SMSDispatch.cpp SMSDispatch.h
g++ -c -fPIC SMSDispatch.cpp -o SMSDispatch.o
g++ -shared SMSDispatch.o -o libSMSDispatch.so
` g++ sms_out.cpp -L. -lSMSDispatch -o sms_out
It works fine if I run the program in the command window with:
LD_LIBRARY_PATH="." ./sms_out
But I want to run it with just ./sms_out, can someone help me?
Tried to add export LD_LIBRARY_PATH=. to the makefile, but that didnt work, just got the error " error while loading shared libraries: libSMSDispatch.so: cannot open shared object file: No such file or directory" when I try to run the program.
Another option - provide -rpath options to linker to inform your binary where else search for dynamic objects.
g++ -Wl,-rpath=<path to .so> -o <your binary here> <cpp file name>.cpp
Add the directory where the .so file exists to LD_LIBRARY_PATH:
$ export LD_LIBRARY_PATH=/dir/containing/sharedobject
A utility you may find useful is ldd, which prints the shared library dependencies. For example:
$ ldd /bin/ls
linux-vdso.so.1 => (0x00007fff819ff000)
librt.so.1 => /lib64/librt.so.1 (0x00007fc0d3f67000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fc0d3d4a000)
libacl.so.1 => /lib64/libacl.so.1 (0x00007fc0d3b42000)
libc.so.6 => /lib64/libc.so.6 (0x00007fc0d37e9000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fc0d35cd000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc0d4170000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fc0d33c9000)
libattr.so.1 => /lib64/libattr.so.1 (0x00007fc0d31c4000)
If shared objects are not locatable a string not found, or similar, is displayed instead of the path to the shared object being used.

How to call Matlab from C++ code?

I am trying to call Matlab functions from C++ code.
With Matlab it comes an example of such code at /extern/examples/eng_mat/engdemo.cpp, however I found no way to build that source code.
Here is the makefile I use:
CFLAGS = -Wall -O3
INCLUDES = -I/opt/Matlab-2009a/extern/include
LIBRARIES = -Wl,-R/opt/Matlab-2009a/bin/glnx86 -L/opt/Matlab-2009a/bin/glnx86 -lmx -lmat -leng
out : engdemo.cpp
g++ $(CFLAGS) $(INCLUDES) -static $^ $(LIBRARIES) -o out
clean :
rm -f out
(Here /opt/Matlab-2009a is my Matlab root.) I am getting a linker error like this:
/usr/bin/ld: cannot find -lmx
collect2: ld returned 1 exit status
make: *** [out] Error 1
And the question is: how can I make g++ to compile engdemo.cpp ?
Note, that the shared library exists:
$ locate libmx.so
/opt/Matlab-2009a/bin/glnx86/libmx.so
/opt/Matlab-2009a/bin/glnx86/libmx.so.csf
and
$ ldd /opt/Matlab-2009a/bin/glnx86/libmx.so
linux-gate.so.1 => (0x004b4000)
libut.so => /opt/Matlab-2009a/bin/glnx86/../../bin/glnx86/libut.so (0x0078f000)
libmwfl.so => /opt/Matlab-2009a/bin/glnx86/../../bin/glnx86/libmwfl.so (0x00110000)
libicudata.so.38 => /opt/Matlab-2009a/bin/glnx86/../../bin/glnx86/libicudata.so.38 (0xb7f82000)
libicuuc.so.38 => /opt/Matlab-2009a/bin/glnx86/../../bin/glnx86/libicuuc.so.38 (0x00bee000)
libicui18n.so.38 => /opt/Matlab-2009a/bin/glnx86/../../bin/glnx86/libicui18n.so.38 (0x001f7000)
libicuio.so.38 => /opt/Matlab-2009a/bin/glnx86/../../bin/glnx86/libicuio.so.38 (0x00e1c000)
libz.so.1 => /usr/lib/libz.so.1 (0x0098e000)
libstdc++.so.6 => /opt/Matlab-2009a/bin/glnx86/../../sys/os/glnx86/libstdc++.so.6 (0x00531000)
libm.so.6 => /lib/libm.so.6 (0x00194000)
libgcc_s.so.1 => /opt/Matlab-2009a/bin/glnx86/../../sys/os/glnx86/libgcc_s.so.1 (0x00eaa000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00900000)
libc.so.6 => /lib/libc.so.6 (0x00345000)
librt.so.1 => /lib/librt.so.1 (0x00964000)
libdl.so.2 => /lib/libdl.so.2 (0x0014e000)
libexpat.so.1 => /opt/Matlab-2009a/bin/glnx86/../../bin/glnx86/../../bin/glnx86/libexpat.so.1 (0x00152000)
libboost_thread-gcc42-mt-1_36.so.1.36.0 => /opt/Matlab-2009a/bin/glnx86/../../bin/glnx86/../../bin/glnx86/libboost_thread-gcc42-mt-1_36.so.1.36.0 (0x00fc2000)
libboost_signals-gcc42-mt-1_36.so.1.36.0 => /opt/Matlab-2009a/bin/glnx86/../../bin/glnx86/../../bin/glnx86/libboost_signals-gcc42-mt-1_36.so.1.36.0 (0x0017d000)
libboost_system-gcc42-mt-1_36.so.1.36.0 => /opt/Matlab-2009a/bin/glnx86/../../bin/glnx86/../../bin/glnx86/libboost_system-gcc42-mt-1_36.so.1.36.0 (0x00a06000)
/lib/ld-linux.so.2 (0x001db000)
So, how can I make g++ to compile engdemo.cpp ?
Assuming $MATLABROOT is the path to MATLAB:
$MATLABROOT/bin/mex -f $MATLABROOT/bin/engopts.sh engdemo.cpp
If you add the -v switch, the verbose output will show you what commands are being used to compile the engine application.
Why are you compiling with -static? From "man gcc":
-static
On systems that support dynamic linking, this prevents linking with the shared libraries. On other systems, this option has no effect.
In other words, the -static option forces the linker to only consider static libraries, meaning that it will try to find libmx.a rather than libmx.so. Since Matlab only ships with shared (dynamic) libraries, it fails.
Try removing that option & see what happens.
If that doesn't work, you may need to run libtool to help it find the .so's at runtime.
I thought I'd post something that related that might be of use to someone who stumbles upon this post in the future, on the theme of calling a Matlab function from C++.
In a tutorial posted on the Mathworks site the use of shared libraries is demonstrated for calling Matlab function(s) from a C++ file. Here, the mcc command is used to create a shared library.
Subsequently, the mbuild command is used to build the executable. However, if you have a complicated C++ code, which itself needs its own set of shared libraries for compilation, mbuild won't work. The tutorial doesn't demonstrate what needs to be done in this case. So, the purpose of my reply is to post that solution. The user C++ file is vigenere.cpp, and the shared library to be linked in this case is libvigenere.so, and this is the resultant call to g++:
g++ -o vigenere -L/usr/local/MATLAB/R2013b/runtime/glnxa64 -L. -I/usr/local/MATLAB/R2013b/extern/include/ vigenere.cpp -lmwmclmcrrt -lm -lvigenere
Some prerequisites:
The Matlab Compiler Runtime (MCR) needs to be installed. Either type mcrinstaller at the Matlab prompt, or download the appropriate installer from the Matlab site.
After doing this, make sure to set your LD_LIBRARY_PATH as per the instructions at the end of the installer.
The current working directory needs to be added to the LD_LIBRARY_PATH. In bash, I do this by export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD
Note that 1&2 are also described in a readme.txt file generated by the mcc command.