问题如标题,本人的OTL连接myodbc报了一些
undefined   reference   to   `SQLFreeHandle 之类的链接错误,参考OTL在linux环境下的说明,上面写的是ODBC Bridge Specific,所以请大家指教,谢谢

解决方案 »

  1.   

    1.测试在Linux下使用otl,所以程序里对数据库没有多少操作
    testdb.cpp文件
    #include <iostream>
    using namespace std;//#define OTL_ODBC
    #define OTL_ODBC_MYSQL
    #define  OTL_ODBC_UNIX
    #include "./otlv4.h"
    otl_connect db;
    int main()
    {
      // otl_connect::otl_initialize();
    try
    {
      // db.rlogon("UID=root;PWD= ;DSN=testdb");
    // cout<<"connect successful"<<endl;
    }
    catch (...)
    {
      // cout<<"error!"<<endl;
    }
    return 0;
    }
    2.使用ace里面的mpc.pl工具,所以要写mpc文件
    testdb.mpc文件
    project (Test_DB):aceexe{
     exename = Test_DB 
     Source_Files{
       dbtest.cpp
     }
     Header_Files{
       otlv4.h
     }
    }
    3.将mpc文件转成makefile文件
    通过命令mpc.pl -type gnuace testdb.mpc
    生成GNUmakefile.Test_DB
    4.编译makefile文件
    gmake -f GNUmakefile.Test_DB
    出错如下:
    GNUmakefile: /home/sqq/test/GNUmakefile.Test_DB MAKEFLAGS=g++ -fvisibility=hidden -fvisibility-inlines-hidden -W -Wall -Wpointer-arith -O3 -g -pipe    -pipe -D_REENTRANT -DACE_HAS_AIO_CALLS -D_GNU_SOURCE   -I/home/sqq/ACE_wrappers -DACE_HAS_EXCEPTIONS -D__ACE_INLINE__ -I/home/sqq/ACE_wrappers  -Wl,-E -L/home/sqq/ACE_wrappers/ace -L./ -L/home/sqq/ACE_wrappers/lib -L. -L/home/sqq/ACE_wrappers/lib -o test_DB .obj/dbtest.o -lACE -ldl -lpthread -lrt 
    .obj/dbtest.o: In function `~otl_conn':
    /home/sqq/test/./otlv4.h:8771: undefined reference to `SQLFreeHandle'
    /home/sqq/test/./otlv4.h:8780: undefined reference to `SQLFreeHandle'
    .obj/dbtest.o: In function `otl_conn::commit()':
    /home/sqq/test/./otlv4.h:9301: undefined reference to `SQLEndTran'
    .obj/dbtest.o: In function `otl_conn::logoff()':
    /home/sqq/test/./otlv4.h:9182: undefined reference to `SQLDisconnect'
    .obj/dbtest.o: In function `otl_conn::error(otl_exc&)':
    /home/sqq/test/./otlv4.h:9262: undefined reference to `SQLGetDiagRec'
    .obj/dbtest.o: In function `~otl_conn':
    /home/sqq/test/./otlv4.h:8771: undefined reference to `SQLFreeHandle'
    /home/sqq/test/./otlv4.h:8780: undefined reference to `SQLFreeHandle'
    /home/sqq/test/./otlv4.h:8771: undefined reference to `SQLFreeHandle'
    /home/sqq/test/./otlv4.h:8780: undefined reference to `SQLFreeHandle'
    /home/sqq/test/./otlv4.h:8771: undefined reference to `SQLFreeHandle'
    .obj/dbtest.o:/home/sqq/test/./otlv4.h:8780: more undefined references to `SQLFreeHandle' follow
    .obj/dbtest.o: In function `otl_conn::commit()':
    /home/sqq/test/./otlv4.h:9301: undefined reference to `SQLEndTran'
    .obj/dbtest.o: In function `otl_conn::logoff()':
    /home/sqq/test/./otlv4.h:9182: undefined reference to `SQLDisconnect'
    .obj/dbtest.o: In function `otl_conn::error(otl_exc&)':
    /home/sqq/test/./otlv4.h:9262: undefined reference to `SQLGetDiagRec'
    .obj/dbtest.o: In function `~otl_conn':
    /home/sqq/test/./otlv4.h:8771: undefined reference to `SQLFreeHandle'
    /home/sqq/test/./otlv4.h:8780: undefined reference to `SQLFreeHandle'
    /home/sqq/test/./otlv4.h:8771: undefined reference to `SQLFreeHandle'
    /home/sqq/test/./otlv4.h:8780: undefined reference to `SQLFreeHandle'
    .obj/dbtest.o: In function `otl_conn::commit()':
    /home/sqq/test/./otlv4.h:9301: undefined reference to `SQLEndTran'
    .obj/dbtest.o: In function `otl_conn::logoff()':
    /home/sqq/test/./otlv4.h:9182: undefined reference to `SQLDisconnect'
    .obj/dbtest.o: In function `otl_conn::error(otl_exc&)':
    /home/sqq/test/./otlv4.h:9262: undefined reference to `SQLGetDiagRec'
    .obj/dbtest.o: In function `~otl_conn':
    /home/sqq/test/./otlv4.h:8771: undefined reference to `SQLFreeHandle'
    /home/sqq/test/./otlv4.h:8780: undefined reference to `SQLFreeHandle'
    /home/sqq/test/./otlv4.h:8771: undefined reference to `SQLFreeHandle'
    /home/sqq/test/./otlv4.h:8780: undefined reference to `SQLFreeHandle'
    .obj/dbtest.o: In function `otl_conn::commit()':
    /home/sqq/test/./otlv4.h:9301: undefined reference to `SQLEndTran'
    .obj/dbtest.o: In function `otl_conn::logoff()':
    /home/sqq/test/./otlv4.h:9182: undefined reference to `SQLDisconnect'
    .obj/dbtest.o: In function `otl_conn::error(otl_exc&)':
    /home/sqq/test/./otlv4.h:9262: undefined reference to `SQLGetDiagRec'
    .obj/dbtest.o: In function `~otl_conn':
    /home/sqq/test/./otlv4.h:8771: undefined reference to `SQLFreeHandle'
    /home/sqq/test/./otlv4.h:8780: undefined reference to `SQLFreeHandle'
    /home/sqq/test/./otlv4.h:8771: undefined reference to `SQLFreeHandle'
    /home/sqq/test/./otlv4.h:8780: undefined reference to `SQLFreeHandle'
    .obj/dbtest.o: In function `otl_conn::commit()':
    /home/sqq/test/./otlv4.h:9301: undefined reference to `SQLEndTran'
    .obj/dbtest.o: In function `otl_conn::logoff()':
    /home/sqq/test/./otlv4.h:9182: undefined reference to `SQLDisconnect'
    .obj/dbtest.o: In function `otl_conn::error(otl_exc&)':
    /home/sqq/test/./otlv4.h:9262: undefined reference to `SQLGetDiagRec'
    .obj/dbtest.o: In function `~otl_conn':
    /home/sqq/test/./otlv4.h:8771: undefined reference to `SQLFreeHandle'
    /home/sqq/test/./otlv4.h:8780: undefined reference to `SQLFreeHandle'
    collect2: ld 返回 1
    gmake: *** [test_DB] 错误 15.如果将testdb.cpp里的otl_connect db;一行注释掉,没有错误。
    从网上找原因,有人说是少了库,所以修改mpc文件,加上了libmyodbc3和libodbc库
      编译还是出相同的错。
    project (Test_DB):aceexe{
     exename = test_DB 
     lit_libs += libmyodbc3 libodbc
     Source_Files{
       dbtest.cpp
     }
     Header_Files{
       otlv4.h
     }
    }
    我安装的是unixODBC-2.2.1.tar.gz,mysql-connector_odbc-3.51.26-linux-x86-32bit.tar.gz
    mysql的odbc驱动不是安装版的,通过解压后把lib目录下的文件拷到/usr/lib目录下的。
    网上有人说要加载libodbc32.a、libodbccp32.a、libsqlod.a,我的机子上只有libodbc、libodbc3
    没找到别的类似名字的库。
      

  2.   

    当初为了解决这个问题也弄了好久找半天只能找到这个贴虽然晚了点,为了以后的人方便在这说下,只要在项目中附加项中添加一个myodbc.lib的库文件就OK了,库具体位置在你ODBC的安装位置查找,如果安装没错的话,安装过程可以参考http://www.59012.cn/article/show.asp?id=6326
      

  3.   

    g++ -fvisibility=hidden -fvisibility-inlines-hidden -W -Wall -Wpointer-arith -O3 -g -pipe -pipe -D_REENTRANT -DACE_HAS_AIO_CALLS -D_GNU_SOURCE -I/home/sqq/ACE_wrappers -DACE_HAS_EXCEPTIONS -D__ACE_INLINE__ -I/home/sqq/ACE_wrappers -Wl,-E -L/home/sqq/ACE_wrappers/ace -L./ -L/home/sqq/ACE_wrappers/lib -L. -L/home/sqq/ACE_wrappers/lib -o test_DB .obj/dbtest.o -lACE -ldl -lpthread -lrt  
    这里头,根本就没有-lodbc啊,当然找汪以对应的符号啊建议楼主先用命令行,整体 体会一下gcc(g++)的compile, link先。
      

  4.   

    安装unixODBC的驱动,然后链接时指定-lodbc