Linux c++ error: undefined reference to 'dlopen'
You have to link against libdl, add
-ldl
to your linker options
undefined reference to `dlopen'
Move autocheck.cpp so that it is before the libraries in your command. Libraries are only searched for things that need resolving in files that appear before them. So your command should look like this:
gcc autocheck.cpp -I/usr/lib/qt3/include -I/opt/kde3/include/ -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -lqt-mt -ldl -L/usr/lib/qt3/lib64 -o autocheck
Undefined reference to 'dlsym' and 'dlopen'
Well, I found the answer, I needed -Wl,--no-as-needed
flag before the -ldl
. I had run across this flag before I asked the question, but apparently mistyped it because it hadn't worked for me.
I don't understand why the flag is needed, but the code does finish linking now.
A SO user here says that it has to do with recent (2013 as of the user's post) versions of gcc linking to --as-needed.
Related Topics
Format Number with Commas in C++
Headers Including Each Other in C++
How to Write Log Base(2) in C/C++
What Is the Easiest Way to Parse an Ini File in C++
Returning Temporary Object and Binding to Const Reference
Using a Stl Map of Function Pointers
The Simplest and Neatest C++11 Scopeguard
In C++, What Is a "Namespace Alias"
Computing Length of a C String at Compile Time. Is This Really a Constexpr
How to Increase Thread Priority in Pthreads
Overriding a Base's Overloaded Function in C++
What Does the Q_Object MACro Do? Why Do All Qt Objects Need This MACro
Why Is There Not an Std::Is_Struct Type Trait