zoukankan      html  css  js  c++  java
  • linux c动态库编译好了,不能用。有些方法报(undefined reference)错误。

    今天编译mysql的动态库(libodbc.so)编译过了,但当我编译一个应用服务时需链接用到mysql的动态库时就报错:

    /home/sc/lib/libodbc.so: undefined reference to `mysql_server_init'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_close'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_affected_rows'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_ping'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_real_query'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_set_character_set'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_free_result'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_autocommit'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_fetch_field_direct'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_real_connect'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_store_result'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_field_count'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_commit'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_fetch_row'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_error'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_server_end'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_rollback'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_errno'
    /home/sc/lib/libodbc.so: undefined reference to `mysql_init'

    排错:

    1. 查看动态库mysql相关的方法:nm libodbc.so|grep mysql 

    U   mysql_affected_rows
    U   mysql_autocommit
    U   mysql_close
    U  mysql_commit
    U  mysql_errno
    U  mysql_error
    U    mysql_fetch_field_direct
    U    mysql_fetch_row
    U    mysql_field_count
    U    mysql_free_result
    U    mysql_init
    U    mysql_ping
    U    mysql_real_connect
    U    mysql_real_query
    U    mysql_rollback
    U    mysql_server_end
    U    mysql_server_init
    U    mysql_set_character_set
    U    mysql_store_result

    其实这些方法前面的 'U' 代表:该符号未定义过,需要自其他对象文件中链接进来;

    这时候在看编译mysql动态库所链接的动态库,发现了链接-L$(MYSQL_LIB),链接时(-L是代表库的路径,而我们这个系统现在根本没有这个环境变量),这个估计是同事在调不同mysql版本时改makefile加上的

    将此去掉在重新编译,那些方法前面的 'U' 变成了 'T'代表:该符号放在代码段中,通常是那些全局非静态函数;

  • 相关阅读:
    SQL Server 创建用户自定义数据类型
    用输入法敲打键盘时字体之间的间隔突然变大了,是怎么回事?
    SQL Server 增加自增ID列
    Python安装cv2模块不成功
    Python错误20009:pymssql._pymssql.OperationalError) (20009, b'DB-Lib error message 20009, severity 9: Unable to connect: Adaptive Server is unavailable or does not exist ')
    Python 获取父级目录
    谷歌上网助手Ghelper
    Python连接MySQL数据库
    Python用pandas获取Excel数据
    Python连接MySQL数据库获取数据绘制柱状图
  • 原文地址:https://www.cnblogs.com/samurail/p/2767318.html
Copyright © 2011-2022 走看看