0

I try to connect a DB to C++ with the Connector C++ 8.0. When I compile a really simple code :

#include <iostream>
#include <jdbc.h>

int main(){
    sql::Driver *driver;
    driver = get_driver_instance();
    
    return 0;
}

I get this error:

c:/program files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\newva\AppData\Local\Temp\ccjFB5x8.o:Main.cpp:(.text+0x1f): undefined reference to `check(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
c:/program files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\newva\AppData\Local\Temp\ccjFB5x8.o:Main.cpp:(.text+0x53): undefined reference to `check(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > 
const&)'
collect2.exe: error: ld returned 1 exit status

When I comment the "driver = get_driver_instance();" line, the code compile.

I compile with a Makefile :

MYSQL_CONCPP_DIR = "C:\Program Files\MySQL\Connector C++ 8.0"
CPPFLAGS=-I $(MYSQL_CONCPP_DIR)\include\mysql -L $(MYSQL_CONCPP_DIR)\lib64\vs14
LDLIBS=-lmysqlcppconn
CXXFLAGS=-std=c++20

result.exe:Main.cpp
    g++ Main.cpp ${CXXFLAGS} ${CPPFLAGS} ${LDLIBS} -o result.exe

I am on Windows 10.

gargaranza
  • 13
  • 2
  • You missed `-lmysqlcppconn8-static` and `-lmysqlclient` – 273K Feb 18 '23 at 18:07
  • @273K I don't have mysqlclient.lib. And if I add -lmysqlcppconn8-static or replace -lmysqlcppconn8 by -lmysqlcppconn8-static nothing change – gargaranza Feb 18 '23 at 19:01
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ken White Feb 18 '23 at 19:28

1 Answers1

0

Connector C++ has 2 APIs.

JDBC (the one you are using)

X DevAPI

You are linking with mysqlcppconn8 which is DevAPI. You should link with mysqlcppconn.

Both are bundled on the same package.

Luís Silva
  • 101
  • 2
  • Ok, I didn't know the difference between mysqlcppconn8 and mysqlcppconn, I have 1 less error, the last one, but there are still errors – gargaranza Feb 18 '23 at 21:16
  • You are using GCC on Visual Studio built connector..... That is not possible... You have to use VS. – Luís Silva Feb 19 '23 at 11:40