Undefined reference to 'dlsym'
Asked Answered
T

1

24

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.

Tuberculin answered 4/12, 2013 at 7:38 Comment(0)
T
64

I have found the solution; passing the -Wl,--no-as-needed flag to ld 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.

Tuberculin answered 6/12, 2013 at 8:19 Comment(1)
I'm thinking I have a basic link error having to do with all symbols, finally I search on the whole error message including "dlsym", and find this. And it solves the problem. Hard to believe just how many flags ld has nowBlowzy

© 2022 - 2024 — McMap. All rights reserved.