求windows下经过MinGW编译使用OCILIB的C程序的详细步骤
求windows下通过MinGW编译使用OCILIB的C程序的详细步骤
程序是OCILIB一个简单的例子程序:
#include "ocilib.h"
int main(int argc, char *argv[]){
OCI_Connection * cn;
OCI_Statement * st;
OCI_Resultset * rs;
OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT);
cn = OCI_ConnectionCreate("127.0.0.1/test", "hanlin", "hanlin", OCI_SESSION_DEFAULT);
st = OCI_StatementCreate(cn);
OCI_ExecuteStmt(st, "select intcol, strcol from table");
rs = OCI_GetResultset(st);
while (OCI_FetchNext(rs)){
printf("%i - %s\n", OCI_GetInt(rs, 1), OCI_GetString(rs,2));
}
OCI_Cleanup();
return EXIT_SUCCESS;
}
通过MinGW编译的错误信息如下:
C:\Users\Administrator\Desktop\c>gcc DBTest.c -static -o DBTest -ID:\ocilib-3.12.1-windows\ocilib\include -LD:\ocilib-3.12.1-windows\ocilib\lib32 -lociliba
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0x27): undefined reference to `_OCI_Initialize'
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0x4b): undefined reference to `_OCI_ConnectionCreate'
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0x5b): undefined reference to `_OCI_StatementCreate'
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0x73): undefined reference to `_OCI_ExecuteStmt'
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0x7f): undefined reference to `_OCI_GetResultset'
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0x99): undefined reference to `_OCI_GetString'
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0xaf): undefined reference to `_OCI_GetInt'
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0xcf): undefined reference to `_OCI_FetchNext'
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0xd8): undefined reference to `_OCI_Cleanup'
collect2.exe: error: ld returned 1 exit status
ocilib.h文件在D:\ocilib-3.12.1-windows\ocilib\include下,D:\ocilib-3.12.1-windows\ocilib\lib32下是ocilib[x].lib,ocilib[x].dll,libocilib[x].a x=a,m,w 六个文件,系统是32bit的。
------解决方案--------------------
将源代码的后缀改改再试试。
.c改为.cpp或.cpp改为.c
------解决方案--------------------
* To use OCILIB in a project :
*
* - include "ocilib.h" in your application
* - define call convention (OCI_API) to __stdcall
* - define charset mode (OCI_CHARSET_ANSI
------解决方案--------------------
OCI_CHARSET_MIXED
------解决方案--------------------
OCI_CHARSET_WIDE
------解决方案--------------------
OCI_CHARSET_UFT8)
*
* Note for MinGW users:
* - Precompiled 32bits static libraries libocilib[x].a are provided
* - To use OCILIB dll's, copy/rename import libraries ocilib[x].lib to libocilib[x].lib
* - Add the desired version (static/shared + charset) of the library to the linker options
程序是OCILIB一个简单的例子程序:
#include "ocilib.h"
int main(int argc, char *argv[]){
OCI_Connection * cn;
OCI_Statement * st;
OCI_Resultset * rs;
OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT);
cn = OCI_ConnectionCreate("127.0.0.1/test", "hanlin", "hanlin", OCI_SESSION_DEFAULT);
st = OCI_StatementCreate(cn);
OCI_ExecuteStmt(st, "select intcol, strcol from table");
rs = OCI_GetResultset(st);
while (OCI_FetchNext(rs)){
printf("%i - %s\n", OCI_GetInt(rs, 1), OCI_GetString(rs,2));
}
OCI_Cleanup();
return EXIT_SUCCESS;
}
通过MinGW编译的错误信息如下:
C:\Users\Administrator\Desktop\c>gcc DBTest.c -static -o DBTest -ID:\ocilib-3.12.1-windows\ocilib\include -LD:\ocilib-3.12.1-windows\ocilib\lib32 -lociliba
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0x27): undefined reference to `_OCI_Initialize'
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0x4b): undefined reference to `_OCI_ConnectionCreate'
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0x5b): undefined reference to `_OCI_StatementCreate'
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0x73): undefined reference to `_OCI_ExecuteStmt'
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0x7f): undefined reference to `_OCI_GetResultset'
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0x99): undefined reference to `_OCI_GetString'
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0xaf): undefined reference to `_OCI_GetInt'
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0xcf): undefined reference to `_OCI_FetchNext'
C:\Users\ADMINI~1\AppData\Local\Temp\cc0lamTV.o:DBTest.c:(.text+0xd8): undefined reference to `_OCI_Cleanup'
collect2.exe: error: ld returned 1 exit status
ocilib.h文件在D:\ocilib-3.12.1-windows\ocilib\include下,D:\ocilib-3.12.1-windows\ocilib\lib32下是ocilib[x].lib,ocilib[x].dll,libocilib[x].a x=a,m,w 六个文件,系统是32bit的。
------解决方案--------------------
将源代码的后缀改改再试试。
.c改为.cpp或.cpp改为.c
------解决方案--------------------
* To use OCILIB in a project :
*
* - include "ocilib.h" in your application
* - define call convention (OCI_API) to __stdcall
* - define charset mode (OCI_CHARSET_ANSI
------解决方案--------------------
OCI_CHARSET_MIXED
------解决方案--------------------
OCI_CHARSET_WIDE
------解决方案--------------------
OCI_CHARSET_UFT8)
*
* Note for MinGW users:
* - Precompiled 32bits static libraries libocilib[x].a are provided
* - To use OCILIB dll's, copy/rename import libraries ocilib[x].lib to libocilib[x].lib
* - Add the desired version (static/shared + charset) of the library to the linker options