编辑:这已经足够了,我打开了一个新问题。你可以在这里找到它。
我正在尝试使用OCCI用C++连接到Oracle12c。我正在使用CLion2016.1和支持的Cygwin版本。Windows 7。Oracle即时客户端(基本和sdk)昨天(2016年3月29日)下载
注意: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:Usershunrt.CLion2016.1systemcygwin_cmakebincmake.exe --build C:Usershunrt.CLion2016.1systemcmakegeneratedOracle-6ad0652d6ad0652dDebug --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)JetBrainsCLion 2016.1bincmakebincmake.exe" --build C:Usershunrt.CLion2016.1systemcmakegeneratedOracle-6ad0652d6ad0652dDebug --target Oracle -- -j 8
"C:Program Files (x86)JetBrainsCLion 2016.1bincmakebincmake.exe" -HC:UsershunrtClionProjectsOracle -BC:Usershunrt.CLion2016.1systemcmakegeneratedOracle-6ad0652d6ad0652dDebug --check-build-system CMakeFilesMakefile.cmake 0
C:/MinGW/bin/mingw32-make.exe -f CMakeFilesMakefile2 Oracle
mingw32-make.exe[1]: Entering directory 'C:/Users/hunrt/.CLion2016.1/system/cmake/generated/Oracle-6ad0652d/6ad0652d/Debug'
"C:Program Files (x86)JetBrainsCLion 2016.1bincmakebincmake.exe" -HC:UsershunrtClionProjectsOracle -BC:Usershunrt.CLion2016.1systemcmakegeneratedOracle-6ad0652d6ad0652dDebug --check-build-system CMakeFilesMakefile.cmake 0
"C:Program Files (x86)JetBrainsCLion 2016.1bincmakebincmake.exe" -E cmake_progress_start C:Usershunrt.CLion2016.1systemcmakegeneratedOracle-6ad0652d6ad0652dDebugCMakeFiles 2
C:/MinGW/bin/mingw32-make.exe -f CMakeFilesMakefile2 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 CMakeFilesOracle.dirbuild.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)JetBrainsCLion 2016.1bincmakebincmake.exe" -E cmake_depends "MinGW Makefiles" C:UsershunrtClionProjectsOracle C:UsershunrtClionProjectsOracle C:Usershunrt.CLion2016.1systemcmakegeneratedOracle-6ad0652d6ad0652dDebug C:Usershunrt.CLion2016.1systemcmakegeneratedOracle-6ad0652d6ad0652dDebug C:Usershunrt.CLion2016.1systemcmakegeneratedOracle-6ad0652d6ad0652dDebugCMakeFilesOracle.dirDependInfo.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 CMakeFilesOracle.dirbuild.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:MinGWbing++.exe @CMakeFiles/Oracle.dir/includes_CXX.rsp -std=c++11 -g -o CMakeFilesOracle.dirsrcmain.cpp.obj -c C:UsershunrtClionProjectsOraclesrcmain.cpp
[100%] Linking CXX executable Oracle.exe
"C:Program Files (x86)JetBrainsCLion 2016.1bincmakebincmake.exe" -E cmake_link_script CMakeFilesOracle.dirlink.txt --verbose=1
"C:Program Files (x86)JetBrainsCLion 2016.1bincmakebincmake.exe" -E remove -f CMakeFilesOracle.dir/objects.a
C:MinGWbinar.exe cr CMakeFilesOracle.dir/objects.a @CMakeFilesOracle.dirobjects1.rsp
C:MinGWbing++.exe -std=c++11 -g -Wl,--whole-archive CMakeFilesOracle.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 @CMakeFilesOracle.dirlinklibs.rsp
CMakeFilesOracle.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
CMakeFilesOracle.dirbuild.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
CMakeFilesMakefile2: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'
CMakeFilesMakefile2: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
未找到库OCCI。目前你经过一条绝对的路径,这不是你要走的路。您应该使用CMAKE_PREFIX_PATH
将路径添加到库中。则find_library
将检查来自CMAKE_PREFIX_PATH
的所有路径。
对于您的每个库oraociei12.lib、oci.lib、oranzsbb12.lib、oraocci12.lib,您必须使用自己的find_library。