I have built the mySQL C Connector as per the instructions on the mySQL website here, on an ARM computer running Ubuntu 10. I then copied the built headers and libraries, with correct system links, to the paths specified by mysql_config --cflags and mysql_config --libs. So, I have the following output from my_sql_config --cflags --libs:
-I/usr/local/include
-L/usr/local/lib -lmysql -lpthread
and the following directory trees:
/usr/local/include:
atomic hash.h my_aes.h my_base.h my_dbug.h my_list.h my_pthread.h my_trie.h mysql.h mysys sha2.h t_ctype.h waiting_threads.h
base64.h keycache.h my_alarm.h my_bit.h my_dir.h my_md5.h my_stacktrace.h my_uctype.h mysql_com.h mysys_err.h sql_common.h thr_alarm.h wqueue.h
config-win.h lf.h my_alloc.h my_bitmap.h my_getopt.h my_net.h my_sys.h my_vle.h mysql_time.h queues.h sslopt-case.h thr_lock.h
decimal.h m_ctype.h my_atomic.h my_charsets.h my_global.h my_no_pthread.h my_time.h my_xml.h mysql_version.h service_versions.h sslopt-longopts.h typelib.h
errmsg.h m_string.h my_attribute.h my_config.h my_libwrap.h my_nosys.h my_tree.h myisampack.h mysqld_error.h sha1.h sslopt-vars.h violite.h
/usr/local/lib:
drwxr-xr-x 3 root root 4096 Oct 21 10:19 .
drwxr-xr-x 11 root root 4096 Oct 21 09:38 ..
lrwxrwxrwx 1 root root 14 Oct 21 10:12 libmysql.so -> libmysql.so.16
lrwxrwxrwx 1 root root 18 Oct 21 10:11 libmysql.so.16 -> libmysql.so.16.0.0
-rw-r--r-- 1 root root 2156350 Oct 21 09:56 libmysql.so.16.0.0
-rw-r--r-- 1 root root 2539588 Oct 21 09:56 libmysqlclient.a
lrwxrwxrwx 1 root root 11 Oct 21 10:12 libmysqlclient.so -> libmysql.so
lrwxrwxrwx 1 root root 11 Oct 21 10:13 libmysqlclient_r.so -> libmysql.so
Now, when I try to staticlly compile something, using something like this:
gcc -static -o hello_world $(mysql_config --cflags) hello_world.c $(mysql_config --libs)
I get an error message as follows:
/usr/bin/ld: cannot find -lmysql
collect2: ld returned 1 exit status
Would anyone have any idea as to why my linker cannot find the library when it is in the correct spot and was built on the same platform? Thanks beforehand.
EDIT: When I run the same compile command without the static flag, the complile works OK, however, at runtime I get a error while loading shared libraries: libmysql.so.16: cannot open shared object file: No such file or directory Does anyone know why that may be the case?
You are linking statically against
libmysql.abut you do not have such a library available.Libraries with the suffix
.soare dynamic libraries and libraries with the suffix.aare static libraries.If you create a similar symbolic link which you have for the dynamic library, it will probably work: