编译指令的顺序
来源:互联网 发布:canonmp288清零软件 编辑:程序博客网 时间:2024/05/17 04:07
今天尝试编译 fackbook 的pmysql。
Makefile文件如下
CXXFLAGS+=-Wall -Werror -g -O3 `mysql_config --cflags` `pkg-configglib-2.0 gthread-2.0 --cflags`
LDFLAGS+=`mysql_config --libs_r` `pkg-config glib-2.0 gthread-2.0--libs`
all: pmysql
install: pmysql
install -D pmysql${DESTDIR}/usr/bin/pmysql
clean:
rm -f pmysql
生成的编译命令为:
g++ -Wall -Werror -g -O3 `mysql_config --cflags` `pkg-configglib-2.0 gthread-2.0 --cflags` `mysql_config --libs_r` `pkg-configglib-2.0 gthread-2.0 --libs`pmysql.cc -o pmysql
执行make编译的时候碰到如下错误:
/tmp/ccxpuX6i.o: In function `write_g_string':
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:81: undefinedreference to `g_threads_got_initialized'
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:90: undefinedreference to `g_threads_got_initialized'
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:90: undefinedreference to `g_thread_functions_for_glib_use'
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:81: undefinedreference to `g_thread_functions_for_glib_use'
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:85: undefinedreference to `g_log'
/tmp/ccxpuX6i.o: In function `run_query(char*, st_mysql*, char*,char*)':
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:135: undefinedreference to `mysql_select_db'
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:141: undefinedreference to `mysql_query'
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:145: undefinedreference to `g_string_sized_new'
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:146: undefinedreference to `g_string_sized_new'
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:148: undefinedreference to `mysql_use_result'
。。。。。。
解决办法
将编译指令调整为:
g++ -Wall -Werror -g -O3pmysql.cc -o pmysql`mysql_config --cflags` `pkg-config glib-2.0 gthread-2.0 --cflags``mysql_config --libs_r` `pkg-config glib-2.0 gthread-2.0--libs`
编译就成功了。
原因:
The order of arguments to the linker is significant. Usemysql-config after listing the files that need it. Thelinker will see that cpulogger.o needs mysql_init and look inlibraries listed after it for the symbol. If the libraries werelisted earlier in the arguments they won't be searched again.
也就是说 需要链接的lib什么的 需要放在要生成的 .o 文件之后, 要不链接器不会去找。
引用自
http://stackoverflow.com/questions/10970356/undefined-reference-to-mysql-init
转载注明出自高孝鑫的博客
Makefile文件如下
CXXFLAGS+=-Wall -Werror -g -O3 `mysql_config --cflags` `pkg-configglib-2.0 gthread-2.0 --cflags`
LDFLAGS+=`mysql_config --libs_r` `pkg-config glib-2.0 gthread-2.0--libs`
all: pmysql
install: pmysql
clean:
生成的编译命令为:
g++ -Wall -Werror -g -O3 `mysql_config --cflags` `pkg-configglib-2.0 gthread-2.0 --cflags` `mysql_config --libs_r` `pkg-configglib-2.0 gthread-2.0 --libs`
执行make编译的时候碰到如下错误:
/tmp/ccxpuX6i.o: In function `write_g_string':
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:81: undefinedreference to `g_threads_got_initialized'
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:90: undefinedreference to `g_threads_got_initialized'
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:90: undefinedreference to `g_thread_functions_for_glib_use'
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:81: undefinedreference to `g_thread_functions_for_glib_use'
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:85: undefinedreference to `g_log'
/tmp/ccxpuX6i.o: In function `run_query(char*, st_mysql*, char*,char*)':
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:135: undefinedreference to `mysql_select_db'
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:141: undefinedreference to `mysql_query'
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:145: undefinedreference to `g_string_sized_new'
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:146: undefinedreference to `g_string_sized_new'
/home/gaoxiaoxin/pmysql-repo/pmysql/pmysql/pmysql.cc:148: undefinedreference to `mysql_use_result'
。。。。。。
解决办法
将编译指令调整为:
g++ -Wall -Werror -g -O3
编译就成功了。
原因:
The order of arguments to the linker is significant. Usemysql-config after listing the files that need it. Thelinker will see that cpulogger.o needs mysql_init and look inlibraries listed after it for the symbol. If the libraries werelisted earlier in the arguments they won't be searched again.
也就是说 需要链接的lib什么的 需要放在要生成的 .o 文件之后, 要不链接器不会去找。
引用自
http://stackoverflow.com/questions/10970356/undefined-reference-to-mysql-init
转载注明出自高孝鑫的博客
0 0
- 编译指令的顺序
- DELPHI的编译指令
- Delphi 的编译指令
- Delphi 的编译指令
- Delphi 的编译指令
- DELPHI的编译指令
- Delphi的编译指令
- JSP的编译指令
- Bash指令的运行顺序
- linux指令动作的顺序
- 脚本的编译顺序
- #pragma编译指令的使用
- C编译的伪指令
- Delphi 编译指令的使用方法
- SQLite的编译指令Pragma
- JSP的三个编译指令
- ffmpeg 编译指令的理解
- C#的条件编译指令
- mysql 服务器端关于用户连接方面的…
- ACE 环境搭建 之 Hello word
- swift语言IOS8开发战记19 UIImagePickerController
- Mysql OK包与EOF包中的 server_sta…
- 重做主从复制(尽量减少对业务的影…
- 编译指令的顺序
- Linux 如何重置root密码
- 配置bzr 在push的时候 &…
- 写个支持多重名section和key的读取…
- 用boost 的program opti…
- 1461错误, mysql_stmt_prepa…
- mysql 主从复制对于事件event…
- Mysql innodb auto_incr…
- 通过cat 数据文件来合并 myisam表