问题
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'
Build Command :
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
Linked Libraries :
-lodbc32
-lPocoDataODBC
-lws2_32
-lPocoFoundation
-lPocoData
Source Code :
#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;
}
Platform: x64
OS: Windows 10 Pro
Development Environment: Msys64 (mingw-w64 )
IDE: Netbeans
Compiler: mingw-w64-x86_64-gcc 7.3.0-2
回答1:
I asked for the same problem here, but I've found the solution myself (also published in my question):
When compiling files for Data/ODBC I got some warnings, something like
redeclared without dllimport attribute: previous dllimport ignored
for files Data\ODBC\src\Extractor.cpp
and Data\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.
The solution is to add #include "Poco/Foundation.h"
at the beginning of Data\ODBC\src\Extractor.cpp
and Data\ODBC\src\Preparator.cpp
.
I could guess this from this poco issue.
来源:https://stackoverflow.com/questions/50168733/poco-odbc-library-undefined-reference-error