我在 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
没有。 进程返回 255 (0xFF)
。
程序在这一行失败:
con = driver->connect("TCP://127.0.0.1:3306", "test", "test");
任何人都可以帮助它工作吗?
最佳答案
con = driver->connect("TCP:://127.0.0.1:3306", "test", "test");
你有上面的代码,MySQL 网站有下面的代码。
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
我看不出有什么区别。您确定用户名、密码和端口与您在代码中提到的相同吗?
关于c++ - EXE 编译后停止工作。 (Mysql C++ 连接器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26314248/