2014-10-11 73 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

相關問題