C++ (gcc) dyld: Library not loaded: #loader_path/libssl.1.1.dylib - c++

I am trying to link to a dynamic library on MacOs using gcc (C++). When I compile, there are no issues. But when I try running the program, this is what I get:
dyld: Library not loaded: #loader_path/libssl.1.1.dylib
I haven't moved the library from its directory, so I have no idea how to fix this. What should I do? (If you need more information, let me know as I would be happy to provide it)

Related

Linker error for Raspberry Crosscompile

So I installed the toolchain given by raspberry which works good , I managed to compile the library used by the GUI
I have installed all dependancies for the GUI using
xapt -a armhf -m [packet]
But when the linker has to link all librairies it give me the following error and I'm stuck.
arm-linux-gnueabihf-ld: pkcs11dialogs.o: undefined reference to symbol '_Znwj##GLIBCXX_3.4'
/usr/arm-linux-gnueabihf/lib/libstdc++.so.6: error adding symbols: DSO missing from command line
Any help will be very appreciate !
Merci !
The problem is that you're compiling C++ code and not C. C++ needs a runtime support library, the native GCC library is called libstdc++ and you need to link with that.
It's very easy to do: Use the g++ (arm-linux-gnueabihf-g++ in your case) frontend program to link as well as compile., it will automatically add the C++ runtime library. Or add it manually to your linker command.

Build issues with libzbar based Qt application

I am using libzbarQT (libzbarQT.so) in my QT code.I am facing an error while building the code saying "undefined reference to QWidget::qwsEvent(QWSEvent *event)".I am not using this function in my QT code.I want to know which function is internally calling this function so that I can tweak the library a bit.
Any suggestions please..
Thanks in advance for any help.
PS: I am crosscompiling my code using arm-none-linux-gnueabi-g++ toolchain with LTIB.
To solve error '/usr/lib/libzbarqt.so: undefined reference to QX11Info::display()', I have build Qt with X11.Now I am getting error:libzbarqt.so: undefined reference toQWidget::qwsEvent(QWSEvent*)' error.
In general, you could make sure that the symbols are present in the library unless it is built without symbols. I usually use the nm -a and objdump utilities for that operation.
More to the point: it seems that the zbar dynamic library that you have was built against the embedded version of Qt rather than the desktop Linux.
It is an unfortunate issue that both versions have the same dynamic library file names, so things like ldd cannot be much of help.
You will need to make sure to use exactly the same version of Qt installation that the library was built against. This means, if you use the desktop Linux installation for this, it will not work.

Hiding second level dependencies in shared libraries on Linux with NetBeans

Let me explain my problem: I wrote a shared library libMyLib.so that uses OpenCV libopencv_core.so.
When I write an application that uses my library (libMyLib.so) I would like to hide the use of OpenCV library (i.e. an implicit link) but I'm not able. I have to link explicitly to libopencv_core.so too.
What should I do? Is it possible or I have to link OpenCV statically to my own library to hide it?
I'm using NetBeans 7.3.1 with gcc 4.7.3 and ld 2.23.2.
Thanks for your help!
It should be possible to link the OpenCV library statically. I don't think there's much that can be done to completely hide the OpenCV library symbols in a process that loads the shared library. The following options to ld should work:
ld ... -static -lopencv_core -Bdynamic ...
If calling from cc, then it's like this:
gcc ... -Wl,-static,-lopencv_core,-Bdynamic ...
Another possibility is using dynamic loading of the library with dlopen() and finding symbols with dlsym(). This may work to hide the rest of the library's symbols. Here's an online version of the manpage for those: http://linux.die.net/man/3/dlopen.

libstdc++ GLIBCXX version errors

when I compile a c++ program in my computer using g++ and transfer the executable to run it on my university server, I get
./main: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by ./main)
./main: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by ./main)
./main: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by ./main)
The program runs well on my computer, and I don't have privileges to install any new software on my university servers.
any help ?
Thanks
It seems you are using the standard library as a shared library (default behaviour) when linking your program at home.
So rather than really "linking" the library, your linker just resolves some symbols and does another operation, while delaying the actual loading of the library to run-time.
When you execute your program at your university computer, the loader (the program which actually loads your program in memory and throws the main thread) looks for the libraries your program needs and tries to load them (look for LD_LIBRARY_PATH in linux if you feel curious).
The problem here is that you are linking your program at home with a version of the stdlib that is not the same version as what you have at the university. So when the loader tries to find the library, it fails, and so your program cannot be run.
Solutions:
a) To avoid all these problems use static linking instead of dynamic linking. I am not sure if this is possible with stdlib, but I think it is worth to test it (see: http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html and look for "-static" flag)
b) You can try to compile your program at your university computer so it will use the version there.
c) Try to know which stdlib version is installed there and install the same version in your compiler machine.
d) You can try to copy your home version of stdlib to the same folder your application is. This usually works because the loader tends to search for shared libraries in the current application folder before looking in the path set in the environment variable LD_LIBRARY_PATH (linux)
Hope that helps.
P.S.:
Here you have a nice introduction to static vs shared/dynamic libraries http://www.network-theory.co.uk/docs/gccintro/gccintro_25.html
And here (http://en.wikipedia.org/wiki/Library_%28computing%29) a not so nice but more complete library description.
The version of libstdc++.so.6 is too old on the university computer. You have two options:
Statically link with -static. The C++ library will then be merged into the final binary.
Copy the correct version to somewhere in your home directory, then reference it either by passing -rpath /path/to/library/directory at build time, or setting the LD_LIBRARY_PATH environment variable to point to the directory containing the newer libstdc++.so.6.
You can copy your version of the /usr/lib/libstdc++.so.6 to a subdirectory of your home directory of the server, say ~/lib and then run:
$ LD_LIBRARY_PATH=$HOME/lib ./main
Or if you prefer
$ export LD_LIBRARY_PATH=$HOME/lib
$ ./main
And the program should load your private library instead of the system one.
What platforms are you trying to compile for? i.e. 'Your computer' and your 'University servers' ?
You could try compiling your program with the static linking option. This will generate a statically linked executable with all lib dependencies loaded already.
Cheers,

Boost Regex not playing welll with Snow leopard

So I inherited code written in C++ that uses the Boost library. I could compile (using Code Blocks) and run the code on Linux Ubuntu but when I ported it over to the mac and installed the boost library, I can compile it using code blocks (and specifying the location of the regex libraries) but it won't run.
It just gives me the error:
$ ./BLAH_PD
dyld: Library not loaded: libboost_regex.dylib
Referenced from: /Users/spinach/Desktop/B/BLAH/bin/Release/./BLAH_PD
Reason: image not found
Trace/BPT trap
I'm not sure what to do next but any help would be greatly appreciated.
David
You need to set the DYLD_LIBRARY_PATH environment variable to include the path where you installed the compiled Boost libs.
Did you follow these directions?
Boost.Regex is not a header only library. You will need to install/compile the .dynlib. If you did this, did you remember to correctly link it? (-llibboost_regex -LPATH_TO_BOOST_BIN)