[問題] 請問各位前輩使用C++ Compile成DLL的方式

看板C_and_CPP (C/C++)作者時間11年前 (2014/09/22 13:48), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Eclipse 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) sqlite3 問題(Question): 請問各位前輩使用C++ Compile成DLL的方式(裡面有使用sqlite)要給C call,是否正確? 謝謝~ gcc -O0 -g3 -Wall -c -fmessage-length=0 -o sqlite3.o sqlite3.c g++ -DBUILD_DLL -O0 -g3 -Wall -c -fmessage-length=0 -o test_Cpp2.o test_Cpp2.cpp g++ -shared -otest.dll test_Cpp2.o sqlite3.o 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) test_Cpp2.cpp 內容 #ifdef BUILD_DLL #define EXPORT __declspec(dllexport) #else #define EXPORT __declspec(dllimport) #endif #include <stdio.h> #include <sqlite3.h> #include <stdlib.h> #include <string.h> #include <iostream> #include <windows.h> extern "C" __declspec( dllexport ) double __stdcall add2(char *num) { int rc=0; sqlite3_stmt * stmt; sqlite3 *db ; /* 開啟 database 檔 */ sqlite3_initialize( ); rc = sqlite3_open("test.db", &db); if ( rc != SQLITE_OK) { return 0; } const char *sql = "SELECT * FROM TABLE1 where col1=?"; sqlite3_prepare_v2(db, sql, strlen (sql) + 1, & stmt, NULL); sqlite3_bind_text(stmt, 1, num, -1, SQLITE_TRANSIENT); return 0; while (1) { int s; s = sqlite3_step(stmt); if (s == SQLITE_ROW) { double text2 = sqlite3_column_double(stmt, 1); return text2; } else if (s == SQLITE_DONE) { break; } else { return 0; } } } 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.163.34.50 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1411364901.A.C8B.html

09/24 11:19, , 1F
請問compile的指令是否正確,謝謝
09/24 11:19, 1F
文章代碼(AID): #1K7xWboB (C_and_CPP)
文章代碼(AID): #1K7xWboB (C_and_CPP)