CMake找不到OCCI for C ++ Oracle app

时间:2016-03-29 18:57:41

标签: cmake occi

编辑:已经改变了,我已经开了一个新问题了。 You can find it here


我尝试使用OCCI使用C ++连接到Oracle 12c。我正在使用支持的Cygwin版本的CLion2016.1。 Windows 7.昨天(29M2016)下载了Oracle即时客户端(基本和sdk)

注意:C:/Users/hunrt/libs已添加到我的系统路径中。

我只有main.cpp个文件:

#include <occi.h>

using namespace oracle::occi;

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

如果我使用此CMake文件,则会收到以下错误消息。注释掉的find_library()调用是我试图让它工作的不同方式。我得到每个错误消息(我一次只使用一个)。
CMake文件

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: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

如果我删除了find_library()和target_link_libraries()调用,那么我会收到以下错误:

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

我试过的其他事情
我已经尝试将libs,dll和sym文件放在项目中,与CMakeLists.txt文件位于同一目录中,我收到相同的错误消息。


任何帮助表示赞赏。感谢。


根据usr1234567的建议进行修改

CMake文件

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: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



从Cygwin切换到MinGW

CMake文件

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})


使用上面的相同main.cpp我得到以下错误:

"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 个答案:

答案 0 :(得分:0)

找不到图书馆OCCI。目前你传递的是绝对路径,这不是最佳选择。您应该使用CMAKE_PREFIX_PATH添加库的路径。然后find_library会检查CMAKE_PREFIX_PATH的所有路径。

对于您的每个库oraociei12.lib,oci.lib,orannzsbb12.lib,oraocci12.lib,您必须为其自己创建一个find_library。