CMake does not find OCCI for C++ Oracle app

匆匆过客 提交于 2019-12-23 21:14:22

问题


EDIT: Enough has changed from this that I have opened a new question. You can find it here.


I'm trying to connect to Oracle 12c with C++ using OCCI. I am using CLion2016.1 with the supported version of Cygwin. Windows 7. The Oracle instant client (both basic and sdk) were downloaded yesterday (29Mar2016)

Note: C:/Users/hunrt/libs has been added to my system path.

I have just a main.cpp file:

#include <occi.h>

using namespace oracle::occi;

int main()
{
    Environment *env = Environment::createEnvironment(Environment::DEFAULT);
    Environment::terminateEnvironment(env);
}

If I use this CMake file I get the error below. The commented out find_library() calls are the different ways I have tried to get it to work. I get the same error message with each one (I only use one at a time).
CMake file

cmake_minimum_required(VERSION 3.4)
project(Oracle)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

#find_library(OCCI NAMES oraociei12.lib oci.lib orannzsbb12.lib oraocci12.lib PATHS C:/Users/hunrt/libs)
find_library(OCCI NAMES oraociei12.lib oci.lib orannzsbb12.lib oraocci12.lib PATHS /cygdrive/c/Users/hunrt/libs)
#find_library(OCCI NAMES oraociei12 oci orannzsbb12 oraocci12 PATHS C:/Users/hunrt/libs)
#find_library(OCCI NAMES oraociei12.lib ociw32.lib orannzsbb12.lib oraocci12.lib PATHS C:\\Users\\hunrt\\libs)



set(SOURCE_FILES
        src/main.cpp
        include/occi.h)

add_executable(Oracle ${SOURCE_FILES})
target_link_libraries(Oracle ${OCCI})

Error

Error:The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
OCCI
    linked by target "Oracle" in directory /cygdrive/c/Users/hunrt/ClionProjects/Oracle

If I remove the find_library() and target_link_libraries() calls then I get the following error:

C:\Users\hunrt\.CLion2016.1\system\cygwin_cmake\bin\cmake.exe --build C:\Users\hunrt\.CLion2016.1\system\cmake\generated\Oracle-6ad0652d\6ad0652d\Debug --target Oracle -- -j 8
/cygdrive/c/Users/hunrt/.CLion2016.1/system/cygwin_cmake/bin/cmake.exe -H/cygdrive/c/Users/hunrt/ClionProjects/Oracle -B/cygdrive/c/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/make -f CMakeFiles/Makefile2 Oracle
make[1]: Entering directory '/cygdrive/c/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
/cygdrive/c/Users/hunrt/.CLion2016.1/system/cygwin_cmake/bin/cmake.exe -H/cygdrive/c/Users/hunrt/ClionProjects/Oracle -B/cygdrive/c/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug --check-build-system CMakeFiles/Makefile.cmake 0
/cygdrive/c/Users/hunrt/.CLion2016.1/system/cygwin_cmake/bin/cmake.exe -E cmake_progress_start /cygdrive/c/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug/CMakeFiles 2
/usr/bin/make -f CMakeFiles/Makefile2 CMakeFiles/Oracle.dir/all
make[2]: Entering directory '/cygdrive/c/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
/usr/bin/make -f CMakeFiles/Oracle.dir/build.make CMakeFiles/Oracle.dir/depend
make[3]: Entering directory '/cygdrive/c/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
cd /cygdrive/c/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug && /cygdrive/c/Users/hunrt/.CLion2016.1/system/cygwin_cmake/bin/cmake.exe -E cmake_depends "Unix Makefiles" /cygdrive/c/Users/hunrt/ClionProjects/Oracle /cygdrive/c/Users/hunrt/ClionProjects/Oracle /cygdrive/c/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug /cygdrive/c/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug /cygdrive/c/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug/CMakeFiles/Oracle.dir/DependInfo.cmake --color=
make[3]: Leaving directory '/cygdrive/c/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
/usr/bin/make -f CMakeFiles/Oracle.dir/build.make CMakeFiles/Oracle.dir/build
make[3]: Entering directory '/cygdrive/c/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
[ 50%] Linking CXX executable Oracle.exe
/cygdrive/c/Users/hunrt/.CLion2016.1/system/cygwin_cmake/bin/cmake.exe -E cmake_link_script CMakeFiles/Oracle.dir/link.txt --verbose=1
/usr/bin/c++.exe   -std=c++14 -g  -Wl,--enable-auto-import CMakeFiles/Oracle.dir/src/main.cpp.o  -o Oracle.exe -Wl,--out-implib,libOracle.dll.a -Wl,--major-image-version,0,--minor-image-version,0 
CMakeFiles/Oracle.dir/src/main.cpp.o: In function `main':
/cygdrive/c/Users/hunrt/ClionProjects/Oracle/src/main.cpp:7: undefined reference to `oracle::occi::Environment::createEnvironment(oracle::occi::Environment::Mode, void*, void* (*)(void*, unsigned long), void* (*)(void*, void*, unsigned long), void (*)(void*, void*))'
/cygdrive/c/Users/hunrt/ClionProjects/Oracle/src/main.cpp:7:(.text+0x2d): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `oracle::occi::Environment::createEnvironment(oracle::occi::Environment::Mode, void*, void* (*)(void*, unsigned long), void* (*)(void*, void*, unsigned long), void (*)(void*, void*))'
/cygdrive/c/Users/hunrt/ClionProjects/Oracle/src/main.cpp:8: undefined reference to `oracle::occi::Environment::terminateEnvironment(oracle::occi::Environment*)'
/cygdrive/c/Users/hunrt/ClionProjects/Oracle/src/main.cpp:8:(.text+0x3d): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `oracle::occi::Environment::terminateEnvironment(oracle::occi::Environment*)'
collect2: error: ld returned 1 exit status
CMakeFiles/Oracle.dir/build.make:97: recipe for target 'Oracle.exe' failed
make[3]: *** [Oracle.exe] Error 1
make[3]: Leaving directory '/cygdrive/c/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
CMakeFiles/Makefile2:70: recipe for target 'CMakeFiles/Oracle.dir/all' failed
make[2]: *** [CMakeFiles/Oracle.dir/all] Error 2
make[2]: Leaving directory '/cygdrive/c/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/Oracle.dir/rule' failed
make[1]: *** [CMakeFiles/Oracle.dir/rule] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
Makefile:121: recipe for target 'Oracle' failed
make: *** [Oracle] Error 2

Other things I've tried
I've tried putting the libs, dlls and sym files in the project, in the same directory as the CMakeLists.txt file and I get the same error message.


Any help is appreciated. Thanks.


Edit based on suggestion from usr1234567

CMake file

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\\hunrt\\libs)
set(CMAKE_PREFIX_PATH /cygdrive/c/Users/hunrt/libs)

#find_library(OCCI NAMES oraociei12.lib oci.lib orannzsbb12.lib oraocci12.lib  C:/Users/hunrt/libs)
find_library(OCCI NAMES oraociei12.lib oci.lib orannzsbb12.lib oraocci12.lib)
#find_library(OCCI NAMES oraociei12 oci orannzsbb12 oraocci12 PATHS C:/Users/hunrt/libs)
#find_library(OCCI NAMES oraociei12.lib ociw32.lib orannzsbb12.lib oraocci12.lib PATHS C:\\Users\\hunrt\\libs)



set(SOURCE_FILES
        src/main.cpp
        include/occi.h)

add_executable(Oracle ${SOURCE_FILES})
target_link_libraries(Oracle ${OCCI})

Error

Error:The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
OCCI
    linked by target "Oracle" in directory /cygdrive/c/Users/hunrt/ClionProjects/Oracle



Switching from Cygwin to MinGW

CMake file

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\\admatt\\libs)

find_library(OCCI NAMES oraociei12.lib oci.lib orannzsbb12.lib oraocci12.lib)


set(SOURCE_FILES
        src/main.cpp
        include/occi.h)

add_executable(Oracle ${SOURCE_FILES})
target_link_libraries(Oracle ${OCCI})


Using the same main.cpp from above I get the following error:

"C:\Program Files (x86)\JetBrains\CLion 2016.1\bin\cmake\bin\cmake.exe" --build C:\Users\hunrt\.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\hunrt\ClionProjects\Oracle -BC:\Users\hunrt\.CLion2016.1\system\cmake\generated\Oracle-6ad0652d\6ad0652d\Debug --check-build-system CMakeFiles\Makefile.cmake 0
C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\Makefile2 Oracle
mingw32-make.exe[1]: Entering directory 'C:/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
"C:\Program Files (x86)\JetBrains\CLion 2016.1\bin\cmake\bin\cmake.exe" -HC:\Users\hunrt\ClionProjects\Oracle -BC:\Users\hunrt\.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\hunrt\.CLion2016.1\system\cmake\generated\Oracle-6ad0652d\6ad0652d\Debug\CMakeFiles 2
C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\Makefile2 CMakeFiles/Oracle.dir/all
mingw32-make.exe[2]: Entering directory 'C:/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\Oracle.dir\build.make CMakeFiles/Oracle.dir/depend
mingw32-make.exe[3]: Entering directory 'C:/Users/hunrt/.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\hunrt\ClionProjects\Oracle C:\Users\hunrt\ClionProjects\Oracle C:\Users\hunrt\.CLion2016.1\system\cmake\generated\Oracle-6ad0652d\6ad0652d\Debug C:\Users\hunrt\.CLion2016.1\system\cmake\generated\Oracle-6ad0652d\6ad0652d\Debug C:\Users\hunrt\.CLion2016.1\system\cmake\generated\Oracle-6ad0652d\6ad0652d\Debug\CMakeFiles\Oracle.dir\DependInfo.cmake --color=
Scanning dependencies of target Oracle
mingw32-make.exe[3]: Leaving directory 'C:/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
C:/MinGW/bin/mingw32-make.exe -f CMakeFiles\Oracle.dir\build.make CMakeFiles/Oracle.dir/build
mingw32-make.exe[3]: Entering directory 'C:/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
[ 50%] Building CXX object CMakeFiles/Oracle.dir/src/main.cpp.obj
C:\MinGW\bin\g++.exe    @CMakeFiles/Oracle.dir/includes_CXX.rsp -std=c++11 -g   -o CMakeFiles\Oracle.dir\src\main.cpp.obj -c C:\Users\hunrt\ClionProjects\Oracle\src\main.cpp
[100%] Linking CXX executable 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:\MinGW\bin\ar.exe cr CMakeFiles\Oracle.dir/objects.a @CMakeFiles\Oracle.dir\objects1.rsp
C:\MinGW\bin\g++.exe   -std=c++11 -g   -Wl,--whole-archive CMakeFiles\Oracle.dir/objects.a -Wl,--no-whole-archive  -o Oracle.exe -Wl,--out-implib,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/hunrt/ClionProjects/Oracle/src/main.cpp:7: undefined reference to `oracle::occi::Environment::createEnvironment(oracle::occi::Environment::Mode, void*, void* (*)(void*, unsigned int), void* (*)(void*, void*, unsigned int), void (*)(void*, void*))'
C:/Users/hunrt/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 'Oracle.exe' failed
mingw32-make.exe[3]: *** [Oracle.exe] Error 1
mingw32-make.exe[3]: Leaving directory 'C:/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
mingw32-make.exe[2]: *** [CMakeFiles/Oracle.dir/all] Error 2
CMakeFiles\Makefile2:69: recipe for target 'CMakeFiles/Oracle.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/Oracle.dir/rule] Error 2
mingw32-make.exe[2]: Leaving directory 'C:/Users/hunrt/.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/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
Makefile:120: recipe for target 'Oracle' failed
mingw32-make.exe: *** [Oracle] Error 2

回答1:


The library OCCI is not found. Currently you pass an absolute path, which is not the way to go. You should add the path to the library with the CMAKE_PREFIX_PATH. Then find_library will check all paths from CMAKE_PREFIX_PATH.

For each of your libraries oraociei12.lib, oci.lib, orannzsbb12.lib, oraocci12.lib you have to usa a find_library for its own.



来源:https://stackoverflow.com/questions/36292869/cmake-does-not-find-occi-for-c-oracle-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!