Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Oracle External Proc DLL with oci.lib functions built with non-MSVC C compiler (i.e minGW-w64) for W

user11976105Apr 5 2018 — edited Apr 17 2018

Hello,

First of all, we were already able to build a working test DLL using Visual Studio Pro 2010 and able to work with oracle external procedures. The functions would be involving just a simple string replace operation for clobs.

However, since we don't have a Visual Studio Pro license, we and our users can't use this VS Pro setup, we also can't use the Community edition as per its license for organizations.

Given this, we are looking at free C compilers (i.e minGW-w64) for cost cutting.

I would like to inquire if anyone knows/has built a C DLL with minGW-w64 that links with the oci.lib / oci.dll to be used for Oracle external procedures?

I'm able to build a C DLL for external proc usage with minGW-w64 for some test functions that don't have any dependency with oci.lib / oci.dll.

However, our string replace function requires some functions in oci.lib/oci.dll related to clobs so we need to link with the oci.lib / oci.dll library...

I tried 3 different steps (see below) to link to the oci.lib/oci.dll however the DLL doesn't seem to work, when calling the external procedure, ora errors occur.

Machine specs

MinGW-w64 machine which compiles the DLL

Windows 7 64 bit

Oracle DB Server:

Windows 2012 64 bit

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

Setup:

1. Download minGW-w64 (https://mingw-w64.org/doku.php/download/mingw-builds)

Version used is 7.3.0 release, x86_64 arch, posix threads, seh exceptions, rev 0 (choosen arbitrarily based from https://stackoverflow.com/questions/38393755/mingw-w64-offline-installer)

- Verify installed by typing gcc in command prompt (if not, manually add the <mingw-w64>/bin to the env path)

A. Direct link to MSVC oci.lib

gcc -m64 -shared -static -o str-replace.dll debug.c stringops.c preprocess.c -L. -LC:\Users\user\Desktop\OCI\lib\MSVC -loci  -I C:\Users\user\Desktop\OCI\include\

result 18KB (stripped symbols via -s flag) / 54KB,

encountering consistent

ORA-28579 network error during callback from external procedure agent

B. Generate compatible library from OCI DLL

i. Generate definition file for the DLL (generate oci.def)

gendef oci.dll

ii. Generate the static library using the dll and def file  (generate liboci.a)

dlltool -D oci.dll -d oci.def -l output\liboci.a

iii. Include as library during compilation

gcc -m64 -shared -static -o str-replace.dll debug.c stringops.c preprocess.c -L. -LC:\Users\user\Desktop\OCI\lib\MSVC\ocidef\output -loci  -I C:\Users\user\Desktop\OCI\include\ 

result 18KB (stripped symbols via -s flag) / 54KB,

encountering

ORA-06520: PL/SQL: error loading external library

ORA-06522: Unable to load DLL

Ref: https://stackoverflow.com/questions/1984270/use-oracle-oci-dll-with-mingw64-64bit-compiler

Notes: oci.dll is taken from <ORACLE>/BIN (where str-replace.dll is also placed)

C. Generate compatible library from OCI.lib using reimp (will not work as reimp is only 32 bit, can't find any 64-bit reimp)

i. Using reimp, generate static .a library (generate oci.def and liboci.a)

reimp oci.lib

ii. Include as library during compilation

gcc -m64 -shared -static -o str-replace.dll debug.c stringops.c preprocess.c -L. -LC:\Users\user\Desktop\OCI\lib\MSVC\ocireimp\output -loci  -I C:\Users\user\Desktop\OCI\include\

result 18KB (stripped symbols via -s flag) / 54KB,

encountering consistent

ORA-28579 network error during callback from external procedure agent

Ref: http://www.mingw.org/wiki/msvc_and_mingw_dlls

Notes: Reimp executable download link is in above ref

Commandline notes: Ref: https://gcc.gnu.org/onlinedocs/gcc-7.3.0/gcc

-m64 (to output 64 bit dll)

-shared (for generating shared objects e.g dll otherwise may generate executable)

-static / -Wl,-static / -Wl,-Bstatic (to enable static linking)

-o <filename> (output)

-L<path> (add <path> to library search paths)

-l<libname> (add library, no ext needed, it will look for lib<libname>.a or <libname>.lib )

-I <path> (add <path> to include paths, e.g for .h headers files)

1. Can anyone help advise if it is possible to use oci related functions with minGW-w64 compiler? or can you suggest another free for commercial use compiler that works?

For ref, we are using OCIExtProcGetEnv, OCILobOpen, OCILobGetLength2, OCILobGetChunkSize, OCILobClose, OCILobWriteAppend2 OCILobLocator, OCIExtProcContext, OCIEnv, OCISvcCtx, OCIError, OCIStmt, OCIBind, OCIDefine

2. I'm also not able to make the output DLL to be statically linked to oci.lib/liboci.a in the steps above (tried -static / -Wl,-static / -Wl,-Bstatic parameters but file size of the output DLL doesn't change).

Thanks

This post has been answered by user11976105 on Apr 17 2018
Jump to Answer

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 15 2018
Added on Apr 5 2018
1 comment
885 views