MySQL Forums
Forum List  »  Connector/C++

GCC G++/C++ Connect to MySQL on Windows 8.1 (Cygwin)
Posted by: Rajani S
Date: February 14, 2017 07:43AM

Working on the following example, please help connect to MySQL using G++/C++.

https://dev.mysql.com/doc/connector-cpp/en/connector-cpp-examples-complete-example-1.html

$ gcc --version
gcc.exe (tdm64-1) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ --version
g++.exe (tdm64-1) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ c++ --version
c++.exe (tdm64-1) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Aspire@Acer MINGW64 /e/Working/SQL/MySQL/C++
$ g++ -o Example1 Example1.cpp \
> -I /e/Working/SQL/MySQL/C++/Boost/Unix-Variants/boost_1_63_0 \
> -I/e/Working/SQL/MySQL/C++/mysql-connector-c++-noinstall-1.1.8-winx64/include \
> -I/e/Working/SQL/MySQL/C++/mysql-connector-c++-noinstall-1.1.8-winx64/include/cppconn \
> -L/e/Working/SQL/MySQL/C++/mysql-connector-c++-noinstall-1.1.8-winx64/lib/mysqlcppconn
C:\Users\Aspire\AppData\Local\Temp\ccLMCyTM.o:Example1.cpp:(.text+0x4f): undefined reference to `__imp_get_driver_instance'
collect2.exe: error: ld returned 1 exit status


Hence, tried C++ Connector installation from source as in the following: (Installed Boost/CMake/Make) successfully. However, got stuck with the "make clean" step, refer to the following:

https://dev.mysql.com/doc/connector-cpp/en/connector-cpp-installation-source-prerequisites.html

Boost is installed:

http://www.boost.org/doc/libs/1_63_0/more/getting_started/unix-variants.html

$ c++ -I /e/Working/SQL/MySQL/C++/Boost/Unix-Variants/boost_1_63_0 \
> /e/Working/SQL/MySQL/C++/Boost/Unix-Variants/example.cpp \
> -o /e/Working/SQL/MySQL/C++/Boost/Unix-Variants/example \
> /e/Working/SQL/MySQL/C++/Boost/Unix-Variants/boost_1_63_0/Boost-Build/boost/bin.v2/libs/regex/build/gcc-mingw-5.1.0/release/link-static/threading-multi/libboost_regex-mgw51-mt-1_63.a

$ ./example.exe < /e/Working/SQL/MySQL/C++/Boost/Unix-Variants/jayne.txt
Will Success Spoil Rock Hunter?

https://dev.mysql.com/doc/connector-cpp/en/connector-cpp-installation-source-unix.html

"C:\Program Files\CMake\bin\cmake.exe" -G "MinGW Makefiles" -DWITH_BOOST="E:\Working\SQL\MySQL\C++\Boost\Unix-Variants\boost_1_63_0"

E:\Working\SQL\MySQL\C++>git clone https://github.com/mysql/mysql-connector-cpp
Cloning into 'mysql-connector-cpp'...
remote: Counting objects: 16511, done.
remote: Total 16511 (delta 0), reused 0 (delta 0), pack-reused 16511
Receiving objects: 100% (16511/16511), 7.77 MiB | 610.00 KiB/s, done.
Resolving deltas: 100% (13018/13018), done.
Checking connectivity... done.
Checking out files: 100% (739/739), done.

E:\Working\SQL\MySQL\C++>cd mysql-connector-cpp

E:\Working\SQL\MySQL\C++\mysql-connector-cpp>"C:\Program Files\CMake\bin\cmake.exe" -G "MinGW Makefiles" -DWITH_BOOST="E:\Working\SQL\MySQL\C++\Boost\Unix-Varia
nts\boost_1_63_0"
-- The C compiler identification is GNU 5.1.0
-- The CXX compiler identification is GNU 5.1.0
-- Check for working C compiler: C:/TDM-GCC-64/bin/gcc.exe
-- Check for working C compiler: C:/TDM-GCC-64/bin/gcc.exe -- 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: C:/TDM-GCC-64/bin/g++.exe
-- Check for working CXX compiler: C:/TDM-GCC-64/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Building on system: Windows-6.3.9600 (AMD64)
Using cmake generator: MinGW Makefiles
Using 64bit generator
Building shared connector library
-- Boost version: 1.63.0
Configuring CDK as part of MySQL_CONCPP project
WITH_TESTS: OFF
CDK include path: E:/Working/SQL/MySQL/C++/mysql-connector-cpp/cdk/include;E:/Working/SQL/MySQL/C++/mysql-connector-cpp/cdk/include
-- Performing Test HAVE_MOVE_SEMANTICS
-- Performing Test HAVE_MOVE_SEMANTICS - Failed
-- Boost version: 1.63.0
Configuring Protobuf build using cmake generator: MinGW Makefiles
-- The C compiler identification is GNU 5.1.0
-- The CXX compiler identification is GNU 5.1.0
-- Check for working C compiler: C:/TDM-GCC-64/bin/gcc.exe
-- Check for working C compiler: C:/TDM-GCC-64/bin/gcc.exe -- 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: C:/TDM-GCC-64/bin/g++.exe
-- Check for working CXX compiler: C:/TDM-GCC-64/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
Using pthreads for protobuf code
-- Configuring done
-- Generating done
-- Build files have been written to: E:/Working/SQL/MySQL/C++/mysql-connector-cpp/cdk/protobuf
Protobuf include path: E:/Working/SQL/MySQL/C++/mysql-connector-cpp/cdk/protobuf/protobuf-2.6.0/src
WITH_SSL: OFF
-- Performing Test HAVE_STATIC_ASSERT
-- Performing Test HAVE_STATIC_ASSERT - Failed
-- Performing Test HAVE_IS_SAME
-- Performing Test HAVE_IS_SAME - Failed
-- Performing Test HAVE_SHARED_PTR
-- Performing Test HAVE_SHARED_PTR - Failed
-- Looking for sys/endian.h
-- Looking for sys/endian.h - not found
-- Looking for sys/byteorder.h
-- Looking for sys/byteorder.h - not found
-adding static library: cdk_mysqlx_objs
-adding static library: cdk_proto_mysqlx_objs
-adding static library: cdk_foundation_objs
-adding static library: cdk_parser_objs
Merging static libraries into cdk:
- cdk
- protobuf-lite
- cdk_mysqlx_objs
- cdk_proto_mysqlx_objs
- cdk_foundation_objs
- cdk_parser_objs
Wrote configuration header: E:/Working/SQL/MySQL/C++/mysql-connector-cpp/cdk/include/mysql/cdk/config.h
Connector library name: mysqlcppconn2
Connector library will be installed at: lib64
Install location: C:/Users/Aspire/MySQL/MySQL Connector C++ 2.0
-- Configuring done
-- Generating done
-- Build files have been written to: E:/Working/SQL/MySQL/C++/mysql-connector-cpp


E:\Working\SQL\MySQL\C++\mysql-connector-cpp>"C:\Program Files (x86)\GnuWin32\bin\make.exe" clean
cdk/parser/CMakeFiles/cdk_parser.dir/flags.make:6: *** missing separator. Stop.
make[1]: *** [cdk/parser/CMakeFiles/cdk_parser.dir/clean] Error 2
make: *** [clean] Error 2

Please help fix the error.

In a nutshell, how to connect to MySQL using g++/c++ and (not VC++) on Windows without any IDE, the development "environment" being Git Bash/Notepad/MySQL 5.7.14, for Win64 (x86_64)

Thanks

Options: ReplyQuote


Subject
Views
Written By
Posted
GCC G++/C++ Connect to MySQL on Windows 8.1 (Cygwin)
5444
February 14, 2017 07:43AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.