【发布时间】:2017-07-20 01:46:14
【问题描述】:
我在 MySQL 中使用 poco-1.7.7。我在 Ubuntu 上使用 g++ 构建。构建,链接和运行工作正常。 但是,在创建 Data Session 时,会抛出异常“Not found: mysql”:
std::string str = Poco::format("host=%s;user=%s;password=%s;compress=true;auto-reconnect=true;secure-auth=true", _mySQLParams.host, _mySQLParams.user, _mySQLParams.password);
_session = new Poco::Data::Session(Poco::Data::SessionFactory::instance().create(Poco::Data::MySQL::Connector::KEY, str));
mysql 客户端已安装并且是 $PATH 的一部分。
附加信息:我正在使用 Docker 运行 Ubuntu。有关 Makefile,请参见下文。当我在 MacOSX 上编译和运行时,相同的代码可以连接到 MySQL。
你知道这里出了什么问题吗?
来自 Makefile 的片段:
CXX=g++
HEADER_SEARCH_PATH=-I"../../Core/Application/" -I"../../Core/Model/" -I"../../Core/Object/" -I"../../Core/UserInterface/" -I"/usr/local/include/" -I"/usr/include/mysql"
LIB_SEARCH_PATH=-L/usr/local/lib -L/usr/lib/x86_64-linux-gnu
LIBS=-l"PocoJSON" -l"PocoXML" -l"PocoUtil" -l"PocoNet" -l"PocoFoundation" -l"crypto" -l"ssl" -l"PocoCrypto" -l"PocoData" -l"PocoDataMySQL" `pkg-config --libs --cflags icu-uc icu-io`
PPD=-DMPS_MYSQL=1
CXXFLAGS=-std=c++11 -g -m64 -pthread -Wl,--verbose -fabi-version=2 -fno-omit-frame-pointer $(HEADER_SEARCH_PATH) $(PPD)
【问题讨论】:
-
Poco 自带源代码。我确信可以对其进行调试以查看抛出异常的位置和原因。
-
@PaulMcKenzie 感谢您的调试提示。经过大量调试后,我发现由于某种原因 MySQL 连接器没有初始化。显式调用
Poco::Data::MySQL::Connector::registerConnector();解决了这个问题。
标签: c++ mysql linux c++11 poco-libraries