I'm trying to compile a simple program using MySql Connector: Running Simple Query using MinGW. The compilation is successful, and in the linking process the error undefined reference to _imp___ZN3sql5mysql19get_driver_instanceEv , or undefined reference to get_driver_instance() . -LC:/lib/mysql/lib -lmysqlcppconn-static options: -LC:/lib/mysql/lib -lmysqlcppconn-static . In the folder C: / lib / mysql / lib are the library files mysqlcppconn.dll / .lib and mysqlcppconn-static.lib, downloaded from the same site. What am I doing wrong?

  • one
    Well, for starters, the name mysqlcppconn-static.lib is a library for MS VS, not for gcc / g ++. The -lmysqlcppconn-static parameter means that the MinGW linker will search for a file named libmysqlcppconn-static.a . You can try to slip this library by renaming it into the one that is expected or just as an object file with an absolute path (without specifying the -l option), but I think the problems will not end there. These connectors have a bad feature - they are tied to a specific version of Visual Studio .. In general, you can try to assemble the connector yourself in MinGW. And take the connector from MariaDB, not MySQL. - Vladimir
  • @Vladimir and MS VS can link .a files? In case you have to change the compiler. - Igor Makhov
  • Honestly, I have not tried. I do not like MS VS and have almost nothing to do with it. But I suspect that under Windows the format of the libraries .a (from mingw) and .lib are no different than the name. The assumption is that the .lib mingw libraries were usually eaten without problems (I once indulged in the BLAS / LAPACK libraries). Well, if I'm wrong, then maybe someone from the community will explain. - Vladimir
  • In general, library formats for VS and MinGW are not compatible. Moreover, even .a (or .lib) libraries of different versions of compilers may be incompatible with each other. Interoperability of Libraries Created by Different Compiler Brands - zed
  • I downloaded this library in .a format, but the errors have not gone away. - Igor Makhov

0