[英]C++ mySQL Connector static library linking
As a new C++ programmer, I am trying to write a C++ program that interacts with a MySQL database using the MySQL Connector XDevAPI static library. 我无法找出正确的库来链接以使程序编译。 这个(或类似的问题)似乎在 MySQL 连接器中很常见,但是我从 stackoverflow 或 MySQL 论坛上的类似问题中尝试过的解决方案都没有为我工作。
使用vscode的构建环境,我有以下main.cpp:
#include <mysqlx/xdevapi.h>
#include <iostream>
int main () {
std::cout << "Hello World";
};
和tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "shell: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-std=c++11",
"-DSTATIC_CONCPP",
"${file}",
"~/mysql-connector/lib64/libmysqlcppconn8-static.a",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-I",
"~/mysql-connector/include",
"-L",
"/usr/local/lib",
"-lssl",
"-lcrypto",
"-lpthread",
"-lresolv"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
}
}
]
}
这会产生以下命令:
/usr/bin/g++ -std=c++11 <project directory>/main.cpp ~/mysql-connector/lib64/libmysqlcppconn8-static.a -o <project directory>/rapier_control -I ~/mysql-connector/include -L /usr/local/lib -lssl -lcrypto -lpthread -lresolv
编译器抛出以下错误:
/tmp/ccvhrgVJ.o: In function `mysqlx::abi2::r0::string::traits<char>::to_str[abi:cxx11](mysqlx::abi2::r0::string const&)':
main.cpp:(.text._ZN6mysqlx4abi22r06string6traitsIcE6to_strB5cxx11ERKS2_[_ZN6mysqlx4abi22r06string6traitsIcE6to_strB5cxx11ERKS2_]+0x2e): undefined reference to `mysqlx::abi2::r0::string::Impl::to_utf8[abi:cxx11](mysqlx::abi2::r0::string const&)'
collect2: error: ld returned 1 exit status
The terminal process terminated with exit code: 1
我已经尝试以多种方式安装 mySQL 连接器(来自.tar,.deb)并链接来自不同位置的库文件(如 stackoverflow 和 mysql 论坛上的各种论坛帖子所建议的那样),并且似乎有所有列出的库链接,但对我来说,看起来我仍然缺少 mysqlx(XDevAPI 库)中的字符串库。
我正在使用以下软件版本:
我已按照文档中的本指南中的所有适用说明(据我所知): https://dev.mysql.com/doc/connectors/en/connector-cpp-apps-general-considerations.7AFC35FDC70D8EC26
即:
#include <mysqlx/xdevapi.h>
。-DSTATIC_CONCPP
宏。有人有什么想法吗? 提前致谢,如果我的帖子不符合 stackoverflow 标准,请告诉我 - 这是我在这里的第一篇帖子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.