我在Windows 8上使用Code::Blocks 13.12
和MingW 4.8.1
。
我尝试以动态和静态方式链接MySQL C++ Connector 1.1.4
。
编译时没有给出错误,但是当启动exe时它停止工作。
我尝试了以下代码:
#include <iostream>
#include "mysql_connection.h"
#include "cppconn/driver.h"
using namespace sql;
int main() {
Driver *driver;
Connection * con;
std::cout << "1\n";
driver = get_driver_instance();
std::cout << "2\n";
con = driver->connect("TCP://127.0.0.1:3306", "test", "test");
std::cout << "3\n";
return 0;
}
建筑物没有给出错误:
-------------- Build: Debug in mysql_connect (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -fexceptions -g -DCPPCONN_PUBLIC_FUNC= -ID:\Development\Libraries\boost_1_56_0 -c D:\Development\Projects\codeblocks\mysql_connect\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -LD:\Development\Libraries\boost_1_56_0 -o bin\Debug\mysql_connect.exe obj\Debug\main.o "C:\Program Files (x86)\MySQL\Connector.C++ 1.1\lib\opt\mysqlcppconn.lib"
Output file is bin\Debug\mysql_connect.exe with size 66.01 KB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))
以下是gdb
:
Starting debugger: D:\Development\Compiler\MingW\bin\gdb.exe -nx -fullname -quiet -args D:/Development/Projects/codeblocks/mysql_connect/bin/Debug/mysql_connect.exe
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb (GDB) 7.6.1
Child process PID: 4236
In RaiseException () (C:\Windows\SysWOW64\KernelBase.dll)
#13 0x00401468 in _fu1___ZSt4cout () at D:\Development\Projects\codeblocks\mysql_connect\main.cpp:13
D:\Development\Projects\codeblocks\mysql_connect\main.cpp:13:252:beg:0x401468
At D:\Development\Projects\codeblocks\mysql_connect\main.cpp:13
Continuing...
[Inferior 1 (process 4236) exited with code 0377]
Debugger finished with status 0
1
和2
在控制台上成功打印,但3
未成功打印。 Process returned 255 (0xFF)
。
该计划在此行失败:
con = driver->connect("TCP://127.0.0.1:3306", "test", "test");
有人可以帮忙让它发挥作用吗?
答案 0 :(得分:0)
con = driver->connect("TCP:://127.0.0.1:3306", "test", "test");
你有一个以上,MySQL网站有以下代码。
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
我没有看到太大的区别。您确定用户名,密码和端口与您在代码中提到的相同吗?
答案 1 :(得分:0)
好!问题是我的IDE。似乎MySQL Connector C++ 1.1.4
仅与Microsoft Visual C++ 2003
或更高版本一起使用。
如果您遇到同样的问题,只需安装Microsoft Visual C++ 2003
或更新版本并正确链接库。
http://dev.mysql.com/doc/connector-cpp/en/connector-cpp-apps-windows-visual-studio.html