Build error: LNK2019 unresolved external symbol _mysql...

Problem

The following errors appear when compiling in Visual Studio:

error LNK2019: unresolved external symbol _mysql_server_init@12 referenced in function "public: static void __cdecl MySQL::Library_Init(void)" (?Library_Init@MySQL@@SAXXZ)

error LNK2001: unresolved external symbol _mysql_free_result@4

fatal error LNK1120: 43 unresolved externals

... (other similar errors)

Solution

This error occurs when linking against the wrong libmysql.lib.

  1. Download MySQL development files
    1. Packed by us for ease of use however you can use your own MySQL Server install to get libmysql.lib.
  2. Un-zip mysql_lib.zip to a known location, e.g C:/mysql_lib
  3. In the CMake GUI tick the Advanced and Group check-boxes.
  4. Change MYSQL_LIBRARY to "C:/mysql_lib/lib_XX/libmysql.lib" as shown below.
    1. XX is 32 if you are compiling in 32 bits mode (i.e Generator is "Visual Studio 12 2013")
    2. or 64 if you are compiling in 64 bits mode (i.e Generator is "Visual Studio 12 2013 Win64")
  5. Change MYSQL_INCLUDE_DIR to "C:/mysql_lib/include" as shown below.
  6. Press Configure and then Generate.