I tend to compile with gcc, in a bash session, on Windows 7. I use Code::Blocks as my IDE of choice and one of my projects, well, quite a few, use the excellent OCILIB library for accessing Oracle databases, by Vincent Rogier. I can’t recommend this library highly enough.
However, it comes with a Code::Blocks project file to build 32 bit libraries, but I need 64 bits. Here’s how I do it.
None of the following is needed if you use something like Visual C as your compiler. I don’t!
Download the source code
Got to https://github.com/vrogier/ocilib/releases and grab the latest release. Watch out for version 4.6.0 as it will not compile on a system with an Oracle 12.1 client – but I have a fix. Version 4.6.1 (when it’s available) has the fix built in.
You need the file
ocilib-x.x.x-windows.zip, so download it to wherever you keep your source files, and unzip it.
Amend the Supplied Project File
There is a project file called
proj\mingw\ocilib_static_lib_mingw.cbp, so open that in Code::Blocks. You will notice that it has two options – ‘Release – ANSI’ and ‘Release – UNICODE’. I use the ANSI version, but the following gives instructions for both.
The project as supplied uses the built in compiler which is a 32 bit only, version of
gcc. My system has a separately installed version that compiles 32 and 64 bit applications. So I need to change the existing targets to use my compiler instead of the built in one.
Change the Default Compiler
Go to Project -> Build Options.
Select the top level
ocilib_static_lib_mingw option on the left. Do not select either of the two release targets at this stage.
The default, built in 32 bit, compiler is named ‘GNU GCC Compiler’ I need to change this to ‘GNU GCC Compiler 32/64bit (TDM-GCC-64)’ which is the name my separately installed compiler is called. If you are prompted to save the settings, choose ‘Yes’ then ‘OK’ on all the remaining dialogues that pop-up. Finally, ‘OK’ your way back to the main screen.
The compiler has now been changed for all targets currently defined. Now, to add the new 64 bit targets.
Add 64bit Targets.
Go to Project -> Properties and select the ‘Build targets’ tab.
Select ‘Release – ANSI’ on the left and click the ‘Duplicate’ button, change the name to ‘Release 64bit – ANSI’ and ‘OK’.
Select the new target, if not already selected.
Under the ‘Output filename’ option, towards the right side, change the ‘lib32’ to ‘lib64’. Everything else remains the same.
Now repeat the above to create the ‘Release 64bit – UNICODE’ target, and ‘OK’ back to the main screen.
That now gives us 4 targets, but they are all 32 bit at present. We now need to change the compiler options.
Change the Compiler Options
Go to Project -> Build Options and select the very top of the tree –
ocilib_static_lib_mingw. Do not select any of the sub-targets, yet.
On the ‘Compiler settings’ tab, scroll down the options list and make sure that both ‘Target X86 (32bit)’ and ‘Target X86 (64bit)’ are unselected.
Click ‘Release – ANSI’ on the left, and select ‘Target X86 (32bit)’.
Click ‘Release – UNICODE’ on the left, and select ‘Target X86 (32bit)’. Select ‘yes’ if prompted to save changes.
Click ‘Release 64bit – ANSI’ on the left, and select ‘Target X86 (64bit)’. Select ‘yes’ if prompted to save changes.
Click ‘Release 64bit – UNICODE’ on the left, and select ‘Target X86 (64bit)’. Select ‘yes’ if prompted to save changes.
Now ‘OK’ back to the main screen.
Build the Libraries
Now that we have 4 targets, it’s time to build the different libraries. In the main screen, select each of the 4 targets in turn, and then select Build -> Rebuild to make sure that any existing versions are rebuilt with the new compiler and options.
When done, there should be two new files in each of the
lib64 folders, these will be named
Fix 4.6.0 Errors
If you get an error about
OCI_ATTR_COL_PROPERTY_IS_CONID then you need to apply the following fix if release 4.6.1 is not yet available.
Edit the file
src/column.c and change the code to the following at lines 260 onwards – there’s only two lines to add.
259 if (value & OCI_ATTR_COL_PROPERTY_IS_GEN_BY_DEF_ON_NULL)
261 col->props |= OCI_CPF_IS_GEN_BY_DEFAULT_ON_NULL;
264 #if OCI_VERSION_COMPILE >= OCI_18_1
266 if (value & OCI_ATTR_COL_PROPERTY_IS_LPART)
268 col->props |= OCI_CPF_IS_LPART;
271 if (value & OCI_ATTR_COL_PROPERTY_IS_CONID)
273 col->props |= OCI_CPF_IS_CONID;
All that is required is to add the two lines numbered 264 and 275 above, but not the line numbers please! You should now be able to compile the code.
Job done, I can now build 32 and 64 bit versions of my applications to access the databases.