I have seen a lot of similar posts, but tried every trick in the book and am still struggling. Everything was working fine, but after installing/removing wireshark with some components/disselectors it all got messed up. I don't remember exactly which libraries/packages got uninstalled, but probably a lot more than I noticed.
If I create a simple main.cpp file like this one:
#include <SQLAPI.h> int main() { SAConnection con; return 0; }
and try
g++ main.cpp -lsqlapi -ldl
it gives me the following error messages:
/usr/local/lib/libsqlapi.so: undefined reference to `dlsym' /usr/local/lib/libsqlapi.so: undefined reference to `dlerror' /usr/local/lib/libsqlapi.so: undefined reference to `dlopen' /usr/local/lib/libsqlapi.so: undefined reference to `dlclose' collect2: error: ld returned 1 exit status
I have tried to put -ldl before -lsqlapi as some have suggested that the order is important. If I use gcc instead of g++ the error is:
/usr/bin/ld: /tmp/ccwBI4tj.o: undefined reference to symbol '__gxx_personality_v0@@CXXABI_1.3' /usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status
I am able to compile and run the file if SAConnection is removed.
I don't think it has anything to do with SQLAPI, because I experience similar problems with libboost. I don't have a small code example, but when I compile a project that was successfully compiled last week, I get the error:
/usr/bin/ld: debug/components/helloworld/HelloWorld.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv' /usr/lib/x86_64-linux-gnu/libboost_system.so.1.53.0: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status
This project is using a Makefile that has been unchanged, so it has to be something on my system that is not correct. I have tried to reinstall build-essential.
Using Ubuntu 64 bit 13.10 with g++ version 4.8.1.
DESCRIPTION. The dlsym() function shall obtain the address of a symbol defined within an object made accessible through a dlopen() call. The handle argument is the value returned from a call to dlopen() (and which has not since been released via a call to dlclose()), and name is the symbol's name as a character string.
The error: undefined reference to 'main' in C program is a very stupid mistake by the programmer, it occurs when the main() function does not exist in the program. If you used main() function and still the error is there, you must check the spelling of the main() function.
An “Undefined Reference” error occurs when we have a reference to object name (class, function, variable, etc.) in our program and the linker cannot find its definition when it tries to search for it in all the linked object files and libraries.
I have found the solution; setting the -Wl,--no-as-needed
before -ldl
. The new compile command is:
gcc main.cpp -lsqlapi -lstdc++ -Wl,--no-as-needed -ldl
Apparently it has something to do with recent versions of gcc/ld linking with --as-needed
by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With