I started here but so much has changed I thought it best to start a new question, especially since I think the CMake issue in the that question is solved.
Background
I'm trying setup a basic shell of a project that involves connecting a C++ midtier to an Oracle 12c database.
Environment
1. MinGW-64 (x86_64-4.9.1-release-win32-sjlj-rt_v3-rev2)
2. Windows 7 64-bit
3. CLion 2016.1.1 (so I'm using CMake 3.5.1)
4. All of the OCCI DLLs are in system32.
5. Both the libs and the dlls are in C:/Users/hurst/libs
CMakeLists.txt
cmake_minimum_required(VERSION 3.4)
project(Oracle)
#set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
set(CMAKE_PREFIX_PATH C:/Users/hurst/libs)
find_library(OCCI1 oraociei12)
find_library(OCCI2 oci)
find_library(OCCI3 orannzsbb12)
find_library(OCCI4 oraocci12)
set(SOURCE_FILES
src/main.cpp
include/occi.h)
add_executable(Oracle ${SOURCE_FILES})
target_link_libraries(Oracle ${OCCI1} ${OCCI2} ${OCCI3} ${OCCI4})
Code
#include <occi.h>
using namespace oracle::occi;
int main()
{
Environment *env = Environment::createEnvironment();
Environment::terminateEnvironment(env);
}
Error
"C:\Program Files (x86)\JetBrains\CLion 2016.1\bin\cmake\bin\cmake.exe" --build C:\Users\hurst\.CLion2016.1\system\cmake\generated\Oracle-6ad0652d\6ad0652d\Debug --target Oracle -- -j 8
[ 50%] Linking CXX executable C:\Users\hurst\ClionProjects\Oracle\output\Debug\Oracle.exe
CMakeFiles\Oracle.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/hurst/ClionProjects/Oracle/src/main.cpp:7: undefined reference to `oracle::occi::Environment::createEnvironment(oracle::occi::Environment::Mode, void*, void* (*)(void*, unsigned long long), void* (*)(void*, void*, unsigned long long), void (*)(void*, void*))'
C:/Users/hurst/ClionProjects/Oracle/src/main.cpp:8: undefined reference to `oracle::occi::Environment::terminateEnvironment(oracle::occi::Environment*)'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\Oracle.dir\build.make:100: recipe for target 'C:/Users/hurst/ClionProjects/Oracle/output/Debug/Oracle.exe' failed
mingw32-make.exe[3]: *** [C:/Users/hurst/ClionProjects/Oracle/output/Debug/Oracle.exe] Error 1
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Oracle.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/Oracle.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Oracle.dir/rule] Error 2
mingw32-make.exe: *** [Oracle] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Oracle.dir/rule' failed
makefile:117: recipe for target 'Oracle' failed
Any suggestions? Thanks.
Edit
As suggested here is the verbose error output:
"C:\Program Files (x86)\JetBrains\CLion 2016.1\bin\cmake\bin\cmake.exe" --build C:\Users\hurst\.CLion2016.1\system\cmake\generated\Oracle-6ad0652d\6ad0652d\Debug --target Oracle -- -j 8
"C:\Program Files (x86)\JetBrains\CLion 2016.1\bin\cmake\bin\cmake.exe" -HC:\Users\hurst\ClionProjects\Oracle -BC:\Users\hurst\.CLion2016.1\system\cmake\generated\Oracle-6ad0652d\6ad0652d\Debug --check-build-system CMakeFiles\Makefile.cmake 0
C:/Users/hurst/Downloads/x86_64-4.9.1-release-win32-sjlj-rt_v3-rev2/mingw64/bin/mingw32-make.exe -f CMakeFiles\Makefile2 Oracle
mingw32-make.exe[1]: Entering directory 'C:/Users/hurst/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
"C:\Program Files (x86)\JetBrains\CLion 2016.1\bin\cmake\bin\cmake.exe" -HC:\Users\hurst\ClionProjects\Oracle -BC:\Users\hurst\.CLion2016.1\system\cmake\generated\Oracle-6ad0652d\6ad0652d\Debug --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files (x86)\JetBrains\CLion 2016.1\bin\cmake\bin\cmake.exe" -E cmake_progress_start C:\Users\hurst\.CLion2016.1\system\cmake\generated\Oracle-6ad0652d\6ad0652d\Debug\CMakeFiles 2
C:/Users/hurst/Downloads/x86_64-4.9.1-release-win32-sjlj-rt_v3-rev2/mingw64/bin/mingw32-make.exe -f CMakeFiles\Makefile2 CMakeFiles/Oracle.dir/all
mingw32-make.exe[2]: Entering directory 'C:/Users/hurst/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
C:/Users/hurst/Downloads/x86_64-4.9.1-release-win32-sjlj-rt_v3-rev2/mingw64/bin/mingw32-make.exe -f CMakeFiles\Oracle.dir\build.make CMakeFiles/Oracle.dir/depend
mingw32-make.exe[3]: Entering directory 'C:/Users/hurst/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
"C:\Program Files (x86)\JetBrains\CLion 2016.1\bin\cmake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\hurst\ClionProjects\Oracle C:\Users\hurst\ClionProjects\Oracle C:\Users\hurst\.CLion2016.1\system\cmake\generated\Oracle-6ad0652d\6ad0652d\Debug C:\Users\hurst\.CLion2016.1\system\cmake\generated\Oracle-6ad0652d\6ad0652d\Debug C:\Users\hurst\.CLion2016.1\system\cmake\generated\Oracle-6ad0652d\6ad0652d\Debug\CMakeFiles\Oracle.dir\DependInfo.cmake --color=
mingw32-make.exe[3]: Leaving directory 'C:/Users/hurst/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
C:/Users/hurst/Downloads/x86_64-4.9.1-release-win32-sjlj-rt_v3-rev2/mingw64/bin/mingw32-make.exe -f CMakeFiles\Oracle.dir\build.make CMakeFiles/Oracle.dir/build
mingw32-make.exe[3]: Entering directory 'C:/Users/hurst/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
[ 50%] Linking CXX executable C:\Users\hurst\ClionProjects\Oracle\output\Debug\Oracle.exe
"C:\Program Files (x86)\JetBrains\CLion 2016.1\bin\cmake\bin\cmake.exe" -E cmake_link_script CMakeFiles\Oracle.dir\link.txt --verbose=1
"C:\Program Files (x86)\JetBrains\CLion 2016.1\bin\cmake\bin\cmake.exe" -E remove -f CMakeFiles\Oracle.dir/objects.a
C:\Users\hurst\Downloads\x86_64-4.9.1-release-win32-sjlj-rt_v3-rev2\mingw64\bin\ar.exe cr CMakeFiles\Oracle.dir/objects.a @CMakeFiles\Oracle.dir\objects1.rsp
C:\Users\hurst\Downloads\x86_64-4.9.1-release-win32-sjlj-rt_v3-rev2\mingw64\bin\g++.exe -std=c++11 -g -Wl,--whole-archive CMakeFiles\Oracle.dir/objects.a -Wl,--no-whole-archive -o C:\Users\hurst\ClionProjects\Oracle\output\Debug\Oracle.exe -Wl,--out-implib,C:\Users\hurst\ClionProjects\Oracle\output\Debug\libOracle.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\Oracle.dir\linklibs.rsp
CMakeFiles\Oracle.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/hurst/ClionProjects/Oracle/src/main.cpp:7: undefined reference to `oracle::occi::Environment::createEnvironment(oracle::occi::Environment::Mode, void*, void* (*)(void*, unsigned long long), void* (*)(void*, void*, unsigned long long), void (*)(void*, void*))'
C:/Users/hurst/ClionProjects/Oracle/src/main.cpp:8: undefined reference to `oracle::occi::Environment::terminateEnvironment(oracle::occi::Environment*)'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [C:/Users/hurst/ClionProjects/Oracle/output/Debug/Oracle.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Oracle.dir/all] Error 2
CMakeFiles\Oracle.dir\build.make:103: recipe for target 'C:/Users/hurst/ClionProjects/Oracle/output/Debug/Oracle.exe' failed
mingw32-make.exe[3]: Leaving directory 'C:/Users/hurst/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
CMakeFiles\Makefile2:69: recipe for target 'CMakeFiles/Oracle.dir/all' failed
mingw32-make.exe[2]: Leaving directory 'C:/Users/hurst/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
CMakeFiles\Makefile2:81: recipe for target 'CMakeFiles/Oracle.dir/rule' failed
mingw32-make.exe[1]: Leaving directory 'C:/Users/hurst/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
makefile:120: recipe for target 'Oracle' failed
mingw32-make.exe[1]: *** [CMakeFiles/Oracle.dir/rule] Error 2
mingw32-make.exe: *** [Oracle] Error 2
Edit
Based on some reading I've been doing on another SO answer I broke up the target_link_libraries() call so that it's one library per call:
target_link_libraries(Oracle ${OCCI1})
target_link_libraries(Oracle ${OCCI2})
target_link_libraries(Oracle ${OCCI3})
target_link_libraries(Oracle ${OCCI4})
I then tried to run it by moving ${OCCI2} up/down one and see if it succeeds (i.e. 1234, 2134, 1324, 1342) since ${OCCI2} is the OCI lib which represents the base C API of the Oracle interface. It didn't work, same error.