1. windres Lession5.rc Lession5.o
2. g++ -o Lession5.exe Lession5.c Lession5.o
3. g++ -o sample01 sample01.cpp -mwindows (-mwindows 是在windows下執行exe檔案時,不會在跳出一個Console的視窗)
// g++ dos(使用 Notepad++ NppExec 套件的紀錄)
C:\MinGW\bin\g++.exe "$(FULL_CURRENT_PATH)" -o $(NAME_PART)
// g++(使用 Notepad++ NppExec 套件的紀錄)
C:\MinGW\bin\g++.exe "$(FULL_CURRENT_PATH)" -o $(NAME_PART) -mwindows -Wall( -Wall 會顯示程式中是否有無效的參數或函式)
// g++ & rc & comctl32(使用 Notepad++ NppExec 套件的紀錄, 使用Window控制項)
C:\MinGW\bin\windres.exe $(NAME_PART).rc -o $(NAME_PART).o
C:\MinGW\bin\g++.exe "$(FULL_CURRENT_PATH)" -o $(NAME_PART) $(NAME_PART).o "C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib\comctl32.lib" -mwindows -Wall
// g++ & rc(使用 Notepad++ NppExec 套件的紀錄)
C:\MinGW\bin\windres.exe $(NAME_PART).rc -o $(NAME_PART).o
C:\MinGW\bin\g++.exe "$(FULL_CURRENT_PATH)" -o $(NAME_PART) $(NAME_PART).o -mwindows -Wall
// g++ & lib(使用 Notepad++ NppExec 套件的紀錄, 使用Windows Timer套件)
C:\MinGW\bin\g++.exe "$(FULL_CURRENT_PATH)" -o $(NAME_PART) "C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib\WinMM.Lib" -mwindows
// C++ 連結 MySQL 的方法(不使用 Visual C++ 和 .net 的方式)
01. 需要上網抓取 mysql-connector-c-noinstall-6.0.2-win32
02. 參考 http://www.programmer-club.com/showSameTitleN/mysql/911.html
03. 參考 http://www.openwebspider.org/documentation/how-to-link-libmysqllib-with-dev-c-or-gcc-under-windows/
04. 產生 libmysql.a 的方式
> reimp.exe <FULL_PATH_OF(MySQL\lib\opt)>libmysql.lib
(^ This command creates: libmysql.def AND libmysql.a)
> dlltool.exe –input-def LIBMYSQL.def –dllname libmysql.dll –output-lib libmysql.dll
(^ this creates libmysql.dll)
05. 將產生的 libmysql.a 拷貝到 MinGW 的 lib 下
06. 在程式中, 需要 include 兩個檔案
#include <winsock.h> // SOCKET TYPE(for mysql.h)
#include <mysql.h>
07. 可以使用以下程式測試連結是否成功??
using namespace std;
int main(void) {
MYSQL my_connection; //This is a SQL connection.
mysql_init(&my_connection); //initinal mysql connection
if (mysql_real_connect(&my_connection, HOST, USERNAME, PASSWORD, DATABASE, 0, NULL, CLIENT_FOUND_ROWS)) { //connect success
cout << "Connection Success!!\r\n";
mysql_close(&my_connection); //close database connection
} else {
cout << "Connection Fail!!\r\n";
}
getch();
return EXIT_SUCCESS;
}
08. 編譯檔案的時候, 需要在後面加上 -lmysql -lws2_32, 如下:(使用 Notepad++ NppExec 套件的紀錄)
C:\MinGW\bin\g++.exe "$(FULL_CURRENT_PATH)" -o $(NAME_PART) -I "C:\mysql_c\include" -lmysql -lws2_32
例如: C:\MinGW\bin\g++.exe "C:\portable\C++\WinApp\mysqlconn.cpp" -o mysqlconn -I "C:\mysql_c\include" -lmysql -lws2_32 -mwindows
沒有留言:
張貼留言