Код: Выделить всё
g++ -I /usr/include/unixODBC -I . -L /lib64/unixODBC/ -lodbc -o myquery myquery.cc
Я не могу выполнить сборку с помощью CMake 3.29.
Код: Выделить всё
cmake_minimum_required(VERSION 3.16)
project(myquery LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(myquery src/myquery.cc)
# code adapted from:
# https://github.com/SOCI/soci/blob/master/cmake/modules/FindODBC.cmake
### Try Windows Kits ##########################################################
if(WIN32)
# List names of ODBC libraries on Windows
set(ODBC_LIBRARY odbc32.lib)
set(_odbc_lib_names odbc32;)
# List additional libraries required to use ODBC library
if(MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
set(_odbc_required_libs_names odbccp32;ws2_32)
elseif(MINGW)
set(_odbc_required_libs_names odbccp32)
endif()
endif()
### Try unixODBC or iODBC config program ######################################
if (UNIX AND NOT ODBC_CONFIG)
find_program(ODBC_CONFIG
NAMES odbc_config iodbc-config
DOC "Path to unixODBC or iODBC config program")
endif()
if (UNIX AND ODBC_CONFIG)
# unixODBC and iODBC accept unified command line options
execute_process(COMMAND ${ODBC_CONFIG} --cflags
OUTPUT_VARIABLE _cflags OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${ODBC_CONFIG} --libs
OUTPUT_VARIABLE _libs OUTPUT_STRIP_TRAILING_WHITESPACE)
# Collect paths of include directories from CFLAGS
separate_arguments(_cflags NATIVE_COMMAND "${_cflags}")
foreach(arg IN LISTS _cflags)
if("${arg}" MATCHES "^-I(.*)$")
list(APPEND _odbc_include_paths "${CMAKE_MATCH_1}")
endif()
endforeach()
unset(_cflags)
# Collect paths of library names and directories from LIBS
separate_arguments(_libs NATIVE_COMMAND "${_libs}")
foreach(arg IN LISTS _libs)
if("${arg}" MATCHES "^-L(.*)$")
list(APPEND _odbc_lib_paths "${CMAKE_MATCH_1}")
elseif("${arg}" MATCHES "^-l(.*)$")
set(_lib_name ${CMAKE_MATCH_1})
string(REGEX MATCH "odbc" _is_odbc ${_lib_name})
if(_is_odbc)
list(APPEND _odbc_lib_names ${_lib_name})
else()
list(APPEND _odbc_required_libs_names ${_lib_name})
endif()
unset(_lib_name)
endif()
endforeach()
unset(_libs)
endif()
### Try unixODBC or iODBC in include/lib filesystems ##########################
if (UNIX AND NOT ODBC_CONFIG)
# List names of both ODBC libraries, unixODBC and iODBC
set(_odbc_lib_names odbc;iodbc;unixodbc;)
set(_odbc_include_paths
/usr/local/odbc/include)
set(_odbc_lib_paths
/usr/local/odbc/lib)
endif()
# DEBUG
#message("ODBC_CONFIG=${ODBC_CONFIG}")
#message("_odbc_include_hints=${_odbc_include_hints}")
#message("_odbc_include_paths=${_odbc_include_paths}")
#message("_odbc_lib_paths=${_odbc_lib_paths}")
#message("_odbc_lib_names=${_odbc_lib_names}")
### Find include directories ##################################################
find_path(ODBC_INCLUDE_DIR
NAMES sql.h
HINTS ${_odbc_include_hints}
PATHS ${_odbc_include_paths})
if(NOT ODBC_INCLUDE_DIR AND WIN32)
set(ODBC_INCLUDE_DIR "")
endif()
### Find libraries ############################################################
if(NOT ODBC_LIBRARY)
find_library(ODBC_LIBRARY
NAMES ${_odbc_lib_names}
PATHS ${_odbc_lib_paths}
PATH_SUFFIXES odbc)
foreach(_lib IN LISTS _odbc_required_libs_names)
find_library(_lib_path
NAMES ${_lib}
PATHS ${_odbc_lib_paths} # system parths or collected from ODBC_CONFIG
PATH_SUFFIXES odbc)
if (_lib_path)
list(APPEND _odbc_required_libs_paths ${_lib_path})
endif()
unset(_lib_path CACHE)
endforeach()
unset(_odbc_lib_names)
unset(_odbc_lib_paths)
unset(_odbc_required_libs_names)
endif()
### Set result variables ######################################################
set(REQUIRED_VARS ODBC_LIBRARY)
if(NOT WIN32)
list(APPEND REQUIRED_VARS ODBC_INCLUDE_DIR)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ODBC DEFAULT_MSG ${REQUIRED_VARS})
mark_as_advanced(FORCE ODBC_LIBRARY ODBC_INCLUDE_DIR)
if(ODBC_CONFIG)
mark_as_advanced(FORCE ODBC_CONFIG)
endif()
set(ODBC_INCLUDE_DIRS ${ODBC_INCLUDE_DIR})
list(APPEND ODBC_LIBRARIES ${ODBC_LIBRARY})
list(APPEND ODBC_LIBRARIES ${_odbc_required_libs_paths})
### Import targets ############################################################
if(ODBC_FOUND)
if(NOT TARGET ODBC::ODBC)
if(IS_ABSOLUTE "${ODBC_LIBRARY}")
add_library(ODBC::ODBC UNKNOWN IMPORTED)
set_target_properties(ODBC::ODBC PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${ODBC_LIBRARY}")
else()
add_library(ODBC::ODBC INTERFACE IMPORTED)
set_target_properties(ODBC::ODBC PROPERTIES
IMPORTED_LIBNAME "${ODBC_LIBRARY}")
endif()
set_target_properties(ODBC::ODBC PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ODBC_INCLUDE_DIR}")
if(_odbc_required_libs_paths)
set_property(TARGET ODBC::ODBC APPEND PROPERTY
INTERFACE_LINK_LIBRARIES "${_odbc_required_libs_paths}")
endif()
endif()
endif()
#tried this block earlier but did not work either
#-----------------------------------------------------------------------------------------
#find_library(SKODBCLIB libodbcmyS.so REQUIRED PATHS /lib64/unixODBC/libodbcmyS.so)
#target_link_libraries(myquery PUBLIC ${SKODBCLIB})
#set(SKODBCLIB_INCLUDE_DIRS /usr/include)
#target_include_directories(myquery PUBLIC ${SKODBCLIB_INCLUDE_DIRS})
#-----------------------------------------------------------------------------------------
include(GNUInstallDirs)
install(TARGETS myquery
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
Код: Выделить всё
undefined reference to `SQLSetEnvAttr'
undefined reference to `SQLAllocHandle'
undefined reference to `SQLSetConnectAttr'
undefined reference to `SQLDriverConnect'
undefined reference to `SQLAllocHandle'
undefined reference to `SQLExecDirect'
undefined reference to `SQLBindCol'
undefined reference to `SQLBindCol'
undefined reference to `SQLFetch'
undefined reference to `SQLCancel'
undefined reference to `SQLFreeHandle'
undefined reference to `SQLDisconnect'
undefined reference to `SQLFreeHandle'
undefined reference to `SQLFreeHandle'
:-1: error: linker command failed with exit code 1 (use -v to see invocation)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Код: Выделить всё
g++ -I /usr/include/unixODBC -I . -L /lib64/unixODBC/ -lodbc -o myquery myquery.cc
Подробнее здесь: https://stackoverflow.com/questions/791 ... y-on-linux
Мобильная версия