[问题] 请问各位前辈使用C++ Compile成DLL的方式

楼主: jerelee   2014-09-22 13:48:19
开发平台(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):
楼主: jerelee   2014-09-24 11:19:00
请问compile的指令是否正确,谢谢

Links booklink

Contact Us: admin [ a t ] ucptt.com