Poco ODBC库未定义参考错误 [英] Poco ODBC library undefined reference error

查看:297
本文介绍了Poco ODBC库未定义参考错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个使用ODBC与MySQL数据库建立连接的程序.我正在使用Poco-Data-ODBC库.我收到以下错误:

I am in process to build a program that establish connectivity with MySQL database using ODBC. I am using Poco-Data-ODBC library for the same. I am getting the following error :

D:\Hardware\Windows\PocoODBC/PocoODBC.cpp:27: undefined reference to `__imp__ZN4Poco4Data4ODBC9Connector17registerConnectorEv'
D:\Hardware\Windows\PocoODBC/PocoODBC.cpp:34: undefined reference to `__imp__ZN4Poco4Data4ODBC9Connector19unregisterConnectorEv'
D:\Hardware\Windows\PocoODBC/PocoODBC.cpp:41: undefined reference to `__imp__ZN4Poco4Data4ODBC9Connector19unregisterConnectorEv'

构建命令:

g++     -o dist/Debug/Msys64_MinGW-w64_7.3.0-Windows/pocoodbc build/Debug/Msys64_MinGW-w64_7.3.0-Windows/PocoODBC.o build/Debug/Msys64_MinGW-w64_7.3.0-Windows/main.o
-L/C/msys64/mingw64/bin -L/C/Program\ Files/MySQL/Connector.ODBC\ 5.3 -lodbc32 -lPocoDataODBC -lws2_32 -lPocoFoundation -lPocoData

链接库:

-lodbc32

-lodbc32

-lPocoDataODBC

-lPocoDataODBC

-lws2_32

-lPocoFoundation

-lPocoFoundation

-lPocoData

-lPocoData

源代码:

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <cstdint>
#include <windows.h>

#define POCO_WIN32_UTF8

#include <Poco/Event.h>
#include <Poco/Data/Data.h>
#include <Poco/Data/Session.h>
#include <Poco/Data/RecordSet.h>
#include <Poco/Data/ODBC/Connector.h>

Poco::Data::ODBC::Connector::registerConnector();
    //const std::string ConnectionString("DRIVER={MySQL ODBC 8.0 Driver}; SERVER=localhost; DATABASE=test; USER=venu; PASSWORD=venu; OPTION=3;");
    const std::string ConnectionString("Dsn=HamsterPro20 ANSI; USER=root; PASSWORD=tantra@123; OPTION=3;");
    Poco::Data::Session session("ODBC", ConnectionString);
    if(not session.isConnected())
    {
        std::cout << "Session connection failed" << std::endl;
        Poco::Data::ODBC::Connector::unregisterConnector();
        return false;
    }
    else
    {
        std::cout << "Session connection success" << std::endl;
        session.close();
        Poco::Data::ODBC::Connector::unregisterConnector();
        return true;
    }

  • 平台:x64

    • Platform: x64

      操作系统:Windows 10 Pro

      OS: Windows 10 Pro

      开发环境:Msys64(mingw-w64)

      Development Environment: Msys64 (mingw-w64 )

      IDE:Netbeans

      IDE: Netbeans

      编译器:mingw-w64-x86_64-gcc 7.3.0-2

      Compiler: mingw-w64-x86_64-gcc 7.3.0-2

      推荐答案

      我在此处询问了相同的问题,但是我ve自己找到了解决方案(也在我的问题中发表):

      I asked for the same problem here, but I've found the solution myself (also published in my question):

      在为Data/ODBC编译文件时,我收到了一些警告,例如

      When compiling files for Data/ODBC I got some warnings, something like

      redeclared without dllimport attribute: previous dllimport ignored

      用于文件Data\ODBC\src\Extractor.cppData\ODBC\src\Preparator.cpp.

      不管这些警告如何,文件都会被编译.但是生成库时,它缺少入口点,如我的问题中所述.

      Regardless these warnings, the files are compiled. But when the library is generated it lacks of entry points, as exposed in my question.

      解决方案是在Data\ODBC\src\Extractor.cppData\ODBC\src\Preparator.cpp的开头添加#include "Poco/Foundation.h".

      The solution is to add #include "Poco/Foundation.h" at the beginning of Data\ODBC\src\Extractor.cpp and Data\ODBC\src\Preparator.cpp.

      我可以从 poco问题中猜出来.

      这篇关于Poco ODBC库未定义参考错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆