I had a problem when linking to mysqlcppconn (version 8.0.30) (similar to the issue described here).
Here is my code:
mysqlx::Session sess2("localhost", 33060,
"root", "test",
"postManufDB");
Schema mySchema(sess2);
CMakeLists.txt (used to compile my app):
cmake_minimum_required(VERSION 3.5)
project(PostManuf VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CPP_CON_VERSION_MAJOR 8)
set(CPP_CON_LIB mysqlcppconn${CPP_CON_VERSION_MAJOR})
set(FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR "/usr/local/mysql/connector-c++-8.0.30")
set(CPP_CON_LIB_INC ${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/include/)
set(CPP_CON_LIB_LINK ${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/lib64/debug/)
include_directories(${CPP_CON_LIB_INC})
link_directories(${CPP_CON_LIB_LINK})
set(PROJECT_SOURCES
main.cpp
mainwindow.cpp
mainwindow.h
)
add_executable(PostManuf ${PROJECT_SOURCES})
target_link_libraries(PostManuf PRIVATE ${CPP_CON_LIB})
Error:
mainwindow.cpp:(.text+0x3ab6): undefined reference to `mysqlx::abi2::r0::Schema::Schema(mysqlx
::abi2::r0::Session&)'
collect2: error: ld returned 1 exit status
Steps I've followed:
- Download mysqlcppconn binaries and used it for development
- Compiled mysqlcppconn binary from source and linked to it
- Added
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)to CMakeLists.txt, but then I have a lot more errors:
mainwindow.cpp:(.text+0x3bb2): undefined reference to `mysqlx::abi2::r0::Schema::Schema(mysqlx
::abi2::r0::Session&)'
/usr/bin/ld: CMakeFiles/PostManuf.dir/mainwindow.cpp.o: in function `mysqlx::abi2::r0::string:
:traits<char>::from_str(mysqlx::abi2::r0::string&, std::string const&)':
mainwindow.cpp:(.text._ZN6mysqlx4abi22r06string6traitsIcE8from_strERS2_RKSs[_ZN6mysqlx4abi22r0
6string6traitsIcE8from_strERS2_RKSs]+0x23): undefined reference to `mysqlx::abi2::r0::string::
Impl::from_utf8(mysqlx::abi2::r0::string&, std::string const&)'
/usr/bin/ld: CMakeFiles/PostManuf.dir/mainwindow.cpp.o: in function `void mysqlx::abi2::r0::in
ternal::Settings_detail<mysqlx::abi2::r0::internal::Settings_traits>::set<true, mysqlx::abi2::
r0::SessionOption, std::string const&, mysqlx::abi2::r0::SessionOption::Enum, unsigned int&, m
ysqlx::abi2::r0::SessionOption::Enum, mysqlx::abi2::r0::string const&>(mysqlx::abi2::r0::Sessi
onOption, std::string const&, mysqlx::abi2::r0::SessionOption::Enum&&, unsigned int&, mysqlx::
abi2::r0::SessionOption::Enum&&, mysqlx::abi2::r0::string const&)':
mainwindow.cpp:(.text._ZN6mysqlx4abi22r08internal15Settings_detailINS2_15Settings_traitsEE3set
ILb1ENS1_13SessionOptionEJRKSsNS7_4EnumERjSA_RKNS1_6stringEEEEvT0_DpOT1_[_ZN6mysqlx4abi22r08in
ternal15Settings_detailINS2_15Settings_traitsEE3setILb1ENS1_13SessionOptionEJRKSsNS7_4EnumERjS
A_RKNS1_6stringEEEEvT0_DpOT1_]+0xbc): undefined reference to `mysqlx::abi2::r0::internal::Sett
ings_detail<mysqlx::abi2::r0::internal::Settings_traits>::do_set(std::list<std::pair<int, mysq
lx::abi2::r0::Value>, std::allocator<std::pair<int, mysqlx::abi2::r0::Value> > >&&)'
/usr/bin/ld: CMakeFiles/PostManuf.dir/mainwindow.cpp.o: in function `void mysqlx::abi2::r0::in
ternal::Settings_detail<mysqlx::abi2::r0::internal::Settings_traits>::set<true, mysqlx::abi2::
r0::SessionOption, std::string>(mysqlx::abi2::r0::SessionOption, std::string&&)':
mainwindow.cpp:(.text._ZN6mysqlx4abi22r08internal15Settings_detailINS2_15Settings_traitsEE3set
ILb1ENS1_13SessionOptionEJSsEEEvT0_DpOT1_[_ZN6mysqlx4abi22r08internal15Settings_detailINS2_15S
ettings_traitsEE3setILb1ENS1_13SessionOptionEJSsEEEvT0_DpOT1_]+0x56): undefined reference to `
mysqlx::abi2::r0::internal::Settings_detail<mysqlx::abi2::r0::internal::Settings_traits>::do_s
et(std::list<std::pair<int, mysqlx::abi2::r0::Value>, std::allocator<std::pair<int, mysqlx::ab
i2::r0::Value> > >&&)'
/usr/bin/ld: CMakeFiles/PostManuf.dir/mainwindow.cpp.o: in function `void mysqlx::abi2::r0::in
ternal::Settings_detail<mysqlx::abi2::r0::internal::Settings_traits>::set<true, mysqlx::abi2::
r0::SessionOption, mysqlx::abi2::r0::string const&>(mysqlx::abi2::r0::SessionOption, mysqlx::a
bi2::r0::string const&)':
mainwindow.cpp:(.text._ZN6mysqlx4abi22r08internal15Settings_detailINS2_15Settings_traitsEE3set
ILb1ENS1_13SessionOptionEJRKNS1_6stringEEEEvT0_DpOT1_[_ZN6mysqlx4abi22r08internal15Settings_de
tailINS2_15Settings_traitsEE3setILb1ENS1_13SessionOptionEJRKNS1_6stringEEEEvT0_DpOT1_]+0x56):
undefined reference to `mysqlx::abi2::r0::internal::Settings_detail<mysqlx::abi2::r0::internal
::Settings_traits>::do_set(std::list<std::pair<int, mysqlx::abi2::r0::Value>, std::allocator<s
td::pair<int, mysqlx::abi2::r0::Value> > >&&)'
collect2: error: ld returned 1 exit status
I can run the application successfully when using more common classes (e.g. Session).
But when using Schema, I can't link.
CMake configuration to compile mysqlcppconn from source (contains compiler info):
=== Booststrap ===
-- generator: Unix Makefiles
-- build type: Debug
-- ----
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check if the system is big endian
-- Searching 16 bit integer
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Using unsigned short
-- Check if the system is big endian - little endian
-- Configuring done
-- Generating done
-- Build files have been written to: /home/zmpl/tmp/mysql-connector-cpp/build/platform-cache
=== Booststrap done ===
-- Check if the system is big endian
-- Searching 16 bit integer
-- Using unsigned short
-- Check if the system is big endian - little endian
-- BIG_ENDIAN: 0
Building version 8.0.30
Building on system: Linux-5.15.0-46-generic (x86_64)
Using cmake generator: Unix Makefiles
Using toolset:
Building 64bit code
Building shared connector library
Configuring CDK as part of MySQL_CONCPP project
-- Looking for SSL library.
-- found OpenSSL headers at: /usr/include
-- OpenSSL library: /usr/lib/x86_64-linux-gnu/libssl.so
-- OpenSSL crypto library: /usr/lib/x86_64-linux-gnu/libcrypto.so
-- Using OpenSSL version: 1.1.1f
-- Looking for SHA512_DIGEST_LENGTH
-- Looking for SHA512_DIGEST_LENGTH - found
-- Looking for X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS
-- Looking for X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS - found
-- Looking for SSL_get0_param
-- Looking for SSL_get0_param - found
-- Looking for X509_VERIFY_PARAM_set_hostflags
-- Looking for X509_VERIFY_PARAM_set_hostflags - found
-- Looking for X509_VERIFY_PARAM_set1_host
-- Looking for X509_VERIFY_PARAM_set1_host - found
-- found required X509 extensions
-- Setting up RapidJSON.
Skipping second declaration of config option: THROW_AS_ASSERT (found in: /home/zmpl/tmp/mysql-
connector-cpp/cdk/CMakeLists.txt)
-- Performing Test HAVE_STATIC_ASSERT
-- Performing Test HAVE_STATIC_ASSERT - Success
-- Performing Test HAVE_IS_SAME
-- Performing Test HAVE_IS_SAME - Failed
-- Performing Test HAVE_SHARED_PTR
-- Performing Test HAVE_SHARED_PTR - Success
-- Performing Test HAVE_SYSTEM_ERROR
-- Performing Test HAVE_SYSTEM_ERROR - Success
-- Check size of wchar_t
-- Check size of wchar_t - done
-- Setting up Protobuf.
== configuring external build of protobuf
-- sources at: /home/zmpl/tmp/mysql-connector-cpp/cdk/extra/protobuf
-- generator: Unix Makefiles
-- option CMAKE_BUILD_TYPE: Debug
-- option CMAKE_SYSTEM_NAME: Linux
-- option CMAKE_SYSTEM_VERSION: 5.15.0-46-generic
-- option CMAKE_SYSTEM_PROCESSOR: x86_64
-- option CMAKE_C_COMPILER: /usr/bin/cc
-- option CMAKE_CXX_COMPILER: /usr/bin/c++
-- ----
Not searching for unused variables given on the command line.
-- Check if the system is big endian
-- Searching 16 bit integer
-- Using unsigned short
-- Check if the system is big endian - little endian
-- BIG_ENDIAN: 0
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Performing Test protobuf_HAVE_BUILTIN_ATOMICS
-- Performing Test protobuf_HAVE_BUILTIN_ATOMICS - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/zmpl/tmp/mysql-connector-cpp/build/cdk/protocol/mys
qlx/protobuf
== done configuring external build of protobuf
-- Setting up compression libraries.
== configuring external build of zlib
-- sources at: /home/zmpl/tmp/mysql-connector-cpp/cdk/extra/zlib
-- generator: Unix Makefiles
-- option CMAKE_BUILD_TYPE: Debug
-- option CMAKE_SYSTEM_NAME: Linux
-- option CMAKE_SYSTEM_VERSION: 5.15.0-46-generic
-- option CMAKE_SYSTEM_PROCESSOR: x86_64
-- option CMAKE_C_COMPILER: /usr/bin/cc
-- option CMAKE_CXX_COMPILER: /usr/bin/c++
-- ----
Not searching for unused variables given on the command line.
-- Check if the system is big endian
-- Searching 16 bit integer
-- Using unsigned short
-- Check if the system is big endian - little endian
-- BIG_ENDIAN: 0
-- Check size of off64_t
-- Check size of off64_t - done
-- Looking for fseeko
-- Looking for fseeko - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/zmpl/tmp/mysql-connector-cpp/build/cdk/protocol/mys
qlx/zlib
== done configuring external build of zlib
== configuring external build of lz4
-- sources at: /home/zmpl/tmp/mysql-connector-cpp/cdk/extra/lz4
-- generator: Unix Makefiles
-- option CMAKE_BUILD_TYPE: Debug
-- option CMAKE_SYSTEM_NAME: Linux
-- option CMAKE_SYSTEM_VERSION: 5.15.0-46-generic
-- option CMAKE_SYSTEM_PROCESSOR: x86_64
-- option CMAKE_C_COMPILER: /usr/bin/cc
-- option CMAKE_CXX_COMPILER: /usr/bin/c++
-- ----
Not searching for unused variables given on the command line.
-- Check if the system is big endian
-- Searching 16 bit integer
-- Using unsigned short
-- Check if the system is big endian - little endian
-- BIG_ENDIAN: 0
-- Configuring done
-- Generating done
-- Build files have been written to: /home/zmpl/tmp/mysql-connector-cpp/build/cdk/protocol/mys
qlx/lz4
== done configuring external build of lz4
== configuring external build of zstd
-- sources at: /home/zmpl/tmp/mysql-connector-cpp/cdk/extra/zstd
-- generator: Unix Makefiles
-- option CMAKE_BUILD_TYPE: Debug
-- option CMAKE_SYSTEM_NAME: Linux
-- option CMAKE_SYSTEM_VERSION: 5.15.0-46-generic
-- option CMAKE_SYSTEM_PROCESSOR: x86_64
-- option CMAKE_C_COMPILER: /usr/bin/cc
-- option CMAKE_CXX_COMPILER: /usr/bin/c++
-- ----
Not searching for unused variables given on the command line.
-- Check if the system is big endian
-- Searching 16 bit integer
-- Using unsigned short
-- Check if the system is big endian - little endian
-- BIG_ENDIAN: 0
-- ZSTD_LEGACY_SUPPORT not defined!
-- Configuring done
-- Generating done
-- Build files have been written to: /home/zmpl/tmp/mysql-connector-cpp/build/cdk/protocol/mys
qlx/zstd
== done configuring external build of zstd
-- Looking for sys/endian.h
-- Looking for sys/endian.h - not found
-- Looking for sys/byteorder.h
-- Looking for sys/byteorder.h - not found
Wrote configuration header: /home/zmpl/tmp/mysql-connector-cpp/build/cdk/include/mysql/cdk/con
fig.h
Preparing to merge SHARED library: connector (xapi;devapi)
Connector library name: mysqlcppconn8
Building version 8.0.30
Generating INFO_SRC
Generating INFO_BIN
Install location: /usr/local/mysql/connector-c++-8.0.30
Connector libraries will be installed at: lib64
Project configuration options:
: BUILD_STATIC: OFF
Build static version of connector library
: WITH_SSL: system
Either 'system' to use system-wide OpenSSL library, or custom OpenSSL location. (default : sys
tem)
: WITH_JDBC: OFF
Whether to build a variant of connector library which implements legacy JDBC API
-- Configuring done
-- Generating done