views:

56

answers:

2

Context: I am not certain whether this is my problem or the problem of the server this is running on. I am trying to compile and run a small utility, to become a cron job, that uses the mysql libraries. The program compiles successfully with the following command, no errors or warnings:

gcc my_program.c -o my_program -I /usr/include/mysql/ -L/usr/include/mysql -lmysqlclient -lglib-2.0 -Wall

I added -lglib-2.0 because...

Problem: when I then try to run the program, it aborts with the following error:

./my_program: symbol lookup error: /usr/lib/libmysqlclient.so.15: undefined symbol: strcpy, version GLIBC_2.0

The error happens at runtime, in the following line:

conn = mysql_init(conn);

conn is declared as MYSQL *conn;, this is the first time I use anything from mysql.h (except for the declarations), and strcpy works fine if I use it in my_program.c itself.

The libraries linked from libmysqlclient.so.15 are:

ldd /usr/lib/libmysqlclient.so.15
    linux-gate.so.1 =>  (0xb7ef6000)
    libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb7cf4000)
    libcrypt.so.1 => /lib/tls/i686/cmov/libcrypt.so.1 (0xb7cc2000)
    libnsl.so.1 => /lib/tls/i686/cmov/libnsl.so.1 (0xb7ca9000)
    libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7c84000)
    libz.so.1 => /usr/lib/libz.so.1 (0xb7c6f000)
    libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7b20000)
    /lib/ld-linux.so.2 (0xb7ef7000)

Is there anything I can do in my code, are my compilation or linking parameters missing something, or is there a problem with the dynamic linking of the libmysqlclient.so.15 library that lies within the library itself? If the latter (which I don't think considering that the mysql library is used in other places in the server AFAIK), what can the server's admin do to fix the problem?

+1  A: 

Try passing the -rdynamic flag to gcc.

Since I shouldn't flood the comment section:

GLIBC_2.0 is a macro that is defined in libc.so.6. So on your system, libc.so.6 is GNU's C library implementation.

If you are still running into problems it's very possible that libmysqlclient.so.15 was built against a different version of libc.so.6 and expects different symbols. In that case you may have to rebuild libmysqlclient.so from source to link with the libraries on the system, or see if there is an upgraded version available for your platform.

birryree
Thanks, but this results in the same error :( I realized that there certainly is a libc.so.6 in the /lib/ path, which appears to be the Linux fork, but I don't see a file that could be the GLIBC_2.0 itself - maybe that's just missing? What soname does that library commonly have?
haslo
`GLIBC_2.0` is a macro that is defined in `libc.so.6`. So on your system, `libc.so.6` is GNU's C library implementation. If you are still running into problems it's very possible that `libmysqlclient.so.15` was built against a different version of `libc.so.6` and expects different symbols.
birryree
+1  A: 

My apologies, I found the problem. It was not in fact a symbol lookup error, but a Segmentation Fault. Because I had called mysql_init with an uninitialized conn instead of NULL for the initialization, libmysqlclient must have broken down and, for reasons beyond my limited knowledge of C, produced the wrong error message.

Debugging on another system with a different build of the same OS produced the correct error, which was a lot easier to debug.

haslo