最近有个项目需要生成静态编译的可执行文件,以便在其它linux的机器中运行,开始以为非常简单,直接在编译中加个-static选项不就是了,结果却和我想的太不一样了,下面说下我遇到的问题以及解决的方法。
开始按照设想应该只要在编译中加个-static选项就可以了,不过却报下面的错误:
cc -g -static -o test_server main_server.o main_db.o err_me.o -L/usr/lib/mysql/ -lmysqlclient -lpthread -ldl -lcrypt/usr/bin/ld: cannot find -lmysqlclient/usr/lib/gcc/i686-redhat-linux/4.6.2/http://www.cnblogs.com/../libpthread.a(libpthread.o): In function `sem_open':
(.text+0x6917): warning: the use of `mktemp'is dangerous, better use `mkstemp'collect2: ld returned1exit status
make:*** [test_server] Error 1
说是没有找到-lmysqlclient,应该是没有找到libmysqlclient.a库,然后我到目录/usr/lib/mysql/下去找,只有libmysqlclient.so的动态链接库,因为加了-static后要使用静态库才能编译成功,然后就在网上搜看看有没有libmysqlclient.a的静态库下载。搜了好几个小时一无所获,偶然看到一个也是编译与mysql库有关的程序的选项,发现里面库的路径居然是/usr/local/mysql/lib/,然后我也到这