2014-10-11 55 views
2

在Windows 8上使用Code::Blocks 13.12MingW 4.8.1即可。我尝试以动态和静态方式链接MySQL C++ Connector 1.1.4。 当编译它不会给出错误,但是当启动exe时它会停止工作。EXE在编译后停止工作。 (Mysql C++连接器)

我尝试下面的代码:

#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 

12是在控制台上成功打印,但是3不是。 Process returned 255 (0xFF)

程序无法在这一行:

con = driver->connect("TCP://127.0.0.1:3306", "test", "test"); 
莫非

任何人的帮助,以得到它的工作?

+0

如果我评论它的连接线,它的工作原理。打印1,2,3。 – 2014-10-11 11:58:48

+0

您的防火墙允许传出连接这个EXE? – GSerg 2014-10-11 15:25:01

+0

是的!由“Code :: Blocks”引起的问题。 – 2014-10-11 15:57:07

回答

0
con = driver->connect("TCP:://127.0.0.1:3306", "test", "test"); 

你有一个以上和MySQL网站有以下代码。

con = driver->connect("tcp://127.0.0.1:3306", "root", "root"); 

我没有看到太大的区别。你确定用户名,密码和端口与你在代码中提到的一样吗?

+0

是的,我确定!我可以从其他地方连接到它。 – 2014-10-11 11:55:52