MathGL libmgl.so.7.2.0 not found - c++

I have downloaded and compiled MathGL following the instructions on sourceforge without any errors occuring.
When I ran my first test-program:
(The <> brackets in line 1 seem so delete it but they are there in the code)
#include mgl2/mgl.h
int main(){
mglGraph gr;
gr.FPlot("sin(pi*x)");
gr.WriteFrame("test.png");
}
the compilation with g++ -lmgl went fine.
When trying to run the programm i get:
./a.out: error while loading shared libraries: libmgl.so.7.2.0: cannot open shared object file: No such file or directory
I triple checked to be sure and libmgl.so.7.2.0 is definetely in /usr/local/lib/.
I tried telling g++ this via the -L option but that didn't work either.
Any help would be greatly appreciated

g++ -lmgl -lpng /shitfile.cpp -o /shitfile
care friend

Related

C++ Executable cannot find library at runtime, even though it's in /usr/lib (On Linux)

I'm creating a game in c++ with the Panda3D framework on Ubuntu. All of the Panda3D shared libraries are in /usr/lib/panda3d and all of the headers are in /usr/include/panda3d. I'm compiling with SCons, but I've tried it with gcc and it's the same, so here are the commands:
g++ -o src/main.o -c -fPIC -O2 -std=gnu++11 -I/usr/include/python2.7 -I/usr/include/panda3d -Iinclude src/main.cpp
g++ -o Test src/main.o -L/usr/lib/panda3d -lp3framework -lpanda -lpandafx -lpandaexpress -lpandabullet -lp3dtoolconfig -lp3dtool -lp3direct -lpthread
And here is the error I get when I run the executable:
./Test: error while loading shared libraries: libp3framework.so.1.11: cannot open shared object file: No such file or directory
There isn't much in the code, just initializing a Panda3D window, so I doubt that's the culprit.
As I said before, the libraries are in /usr/lib/panda3d, I've checked about a million times now and it's driving me crazy. I can't think of a single reason why I would get this error. Any help is appreciated :)
Edit:
I was looking through my files and there's a panda3d.conf file in /etc/ld.so.conf.d with one line: /usr/local/lib/x86_64-linux-gnu/panda3d. Does this have anything to do with it?
Edit #2:
I used the path in the above edit as the library path and got the same results, unfortunately.
I can't think of a single reason why I would get this error.
The reason is very simple: the dynamic loader hasn't been told to look in /usr/lib/panda3d for shared libraries, and so doesn't.
You can run your program with:
LD_DEBUG=files,libs ./Test
and observe which directories the loader is searching.
panda3d.conf ... with one line: /usr/local/lib/x86_64-linux-gnu/panda3d
That is the wrong directory (or at least not the one where your libraries are).
One way to fix this is to correct the above path to /usr/lib/panda3d and run sudo ldconfig.
Another way is to add -Wl,-rpath=/usr/lib/panda3d to your link line.

g++ #include file not found compiler error

I'm currently trying to simply link a file called main.cpp with boost in order to do asio(asynchronous input and output). I'm using a makefile in order to compile the C++ code into executable form. However, despite using the -I modifier on my terminal command in Mac OS X, it still cannot find the appropriate directory to search in. Here is my code in Main
#include <asio.hpp>
int main(){
return 1;
}
and here is the makefile command that I am using
all:
g++ -Iboost_1_60_0/boost/ -o main main.cpp
In my file structure, boost_1_60_0, main.cpp, and makefile are all on the top level, where asio is in the folder boost which is in the folder boost_1_60_0. I'm very confused about this and any help would be appreciated! Thanks!
EDIT: Full error is
1 error generated.
make: *** [all] Error 1
iMats-2:SerialC++ wfehrnstrom$ make
g++ -Iboost_1_60_0 -o main main.cpp
main.cpp:2:10: fatal error: 'asio.hpp' file not found
You should use -Iboost_1_60_0 (or, better still, install Boost properly so that it's found automatically under /usr/include/), and write #include <boost/asio.hpp>.
The include directives inside Boost itself will assume this form, so…
BTW, this has nothing to do with exceptions. Presumably it's a compiler error you've seen.

Boost library missing at runtime (Can compile. Can't run)

This is a pretty entry level question but I just can't seem to find any relevant answers.
I can compile this no problem using the following command:
g++ client.cpp -o client -lboost_system -lpthread
When I try to run the program I get the following error:
./client
./client: error while loading shared libraries: libboost_system.so.1.58.0: cannot open shared object file: No such file or directory
this file exists: /usr/local/lib/libboost_system.so
What am I doing wrong here?
You have to set the path where to find the shared object, the command LD_LIBRARY_PATH=path where shared object is will do it. I guess file is somewhere otherwise link would fail.
It should be some linking error,
Try to compile it and create the .o file first.
g++ -C .cpp // here you need to mention the includes from library. -I
And then create the executable,
g++ -O // here you need to mention the path of the library. -l
Incase your prog is correct, it will create the exe else it will show you the error. Incase of linking error, try to include the .h and lib path correctly in the program.
I didn't get a chance to test your answers. Upgraded to ubuntu 15.04 while troubleshooting another unrelated problem which happened to fix this problem aswell.
Thanks anyway.

How do I link the static Stasm library to my program?

Earlier I succesfully compiled Stasm using cmake on Ubuntu 13.10. It gave me the static library libstasm.a.
However, I'm trying to build my own program using Stasm code but every time I try g++ gives me this:
hanna#hanna-HP-650-Notebook-PC:~/Desktop$ g++ -Wall -L/home/hanna/Downloads/stasm4.1.0/build -lstasm stasmtest.cpp -o stasmtest
stasmtest.cpp:7:23: fatal error: stasm_lib.h: No such file or directory
#include "stasm_lib.h"
^
compilation terminated.
I tried compiling the Minimal.cpp example in the external library because that is supposed to show how to use Stasm in my own programs but still I get the same error.
Can someone please tell me what command I should use to link the Stasm library to my program?
Thanks in advance!
You get a compilation error, not a linking one. g++ cannot find the "stasm_lib.h" header. Use -I/path/to/stasm_lib.h as parameter to g++.

xerces-c 2.8 : error while loading shared libraries

I'm trying to compile a program running on an HP UX server on a Red Hat Linux.
It uses xerces-c library to parse xml files. Compilation is ok, but when i try to run it, I get the following message
./a.out: error while loading shared
libraries: libxerces-c.so.28: cannot
open shared object file: No such file
or directory
I wrote a very simple program to try and understand whats going on:
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/TransService.hpp>
#include <xercesc/parsers/SAXParser.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
int main(int argc, char* argv[])
{
return 0;
}
And compiled it like this:
g++ test.cpp
-L./xml/xerces-c_2_8_0/lib -lxerces-c -I./xml/xerces-c_2_8_0/include
Surprisingly the file is actually there:
lib]$ ls
libxerces-c.a libxerces-c.so.28 libxerces-depdom.a libxerces-depdom.so.28
libxerces-c.so libxerces-c.so.28.0 libxerces-depdom.so libxerces-depdom.so.28.0
Any thoughts ? I feel i'm missing something, but don't know what.
Thanks in advance.
run ldd a.out and see if the linker can resolve the right .so file
export LD_LIBRARY_PATH to include the current folder (in the same manner as the PATH variable) and check ldd again
the good way to do what you want is the following one:
g++ test.cpp -Xlinker -R ./xml/xerces-c_2_8_0/lib -lxerces-c -I./xml/xerces-c_2_8_0/include
or
g++ test.cpp -Wl,-rpath ./xml/xerces-c_2_8_0/lib -lxerces-c -I./xml/xerces-c_2_8_0/include
Xlinker or Wl options allow you to use specific linking options, you do not need to modifiy
LD_LIBRARY_PATH
You need to tell the runtime c library where to find the various symbols that arent compiled statically in your code and arent in the usualy /lib and /usr/lib locations.
You do this by adding the path to your shared library to LD_LIBRARY_PATH. In this case, this will be what you have been putting for the -L argument to the compiler.