Question


This is my first question ever posted, so I hope it will be a positive experience :-)
I'm using W7 pro x64 + VS 2012 pro. I wish to link my C++ console project file to the MariaDBClient 1.0.0 (which is functionally equivalent to C/connector MySQL client).
It is very simple and has
- one /include directory for the xx.h includes (which works fine)
- one /lib directory with 1 DLL (libmariadb.dll) and 2 xx.lib files ("libmariadb.lib" most probably for the server and "mariadbclient.lib" for the client (which is the one relevant for my needs)). At compile time, all is OK (so my #include AND Directory includes are OK), but at LINK phase, I get this error message:

"cppconMariaDB02.obj : error LNK2019: unresolved external symbol _mysql_init@4 referenced in function _wmain"

----- Program is: ------------------------

#pragma once

#include "stdafx.h"
#include <mysql.h>

int _tmain(int argc, _TCHAR* argv[])
{
    MYSQL *my; // OK //
    my = mysql_init(NULL); // Will NOT link //

    return 0;
}//end of program

I believe that the issue is not with the connector, but with my mistake in the options for linking to a library. Here is what I set in the project Properties:

Property Page -> Common Properties -> VC++ Directories ->
-> Include Directories = C:\L\SQLClient\mariadb_client-1.0.0-win64\mariadbclient\include;$(IncludePath)
Property Page -> Common Properties -> VC++ Directories ->
  Library Directories = C:\L\SQLClient\mariadb_client-1.0.0-win64\lib;$(LibraryPath)

Property Page -> Common Properties -> C/C++ ->
-> Additional Include Directories =
C:\L\SQLClient\mariadb_client-1.0.0-win64\mariadbclient\include;%(AdditionalIncludeDirectories)

=> Resulting Compile line:
/Yc"stdafx.h" /GS /analyze- /W3 /Gy /Zc:wchar_t /I"C:\L\SQLClient\mariadb_client-1.0.0-
win64\mariadbclient\include" /ZI /Gm /Od /sdl /Fd"Debug\vc110.pdb" /fp:precise /D "WIN32"
 /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope
 /RTC1 /Gd /Oy- /MDd /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\cppconMariaDB02.pch" 

For the linker (which fails):
Property Page -> Common Properties -> Linker -> General ->
Additional Library Directories = 
C:\L\SQLClient\mariadb_client-1.0.0-win64\lib;%(AdditionalLibraryDirectories)

Property Page -> Common Properties -> Linker -> Input ->
Additional Dependencies =
c:\L\SQLClient\mariadb_client-1.0.0-win64\lib\libmariadb.lib;c:\L\SQLClient\mariadb_client-1.0.0-win64\libc:\L\SQLClient\mariadb_client-1.0.0-win64\lib\libmariadb.lib;c:\L\SQLClient\mariadb_client-1.0.0-win64\lib\mariadbclient.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)

This results into the following linker options:
/OUT:"C:\LProj\vs\cppconMariaDB02\Debug\cppconMariaDB02.exe" /MANIFEST /NXCOMPAT 
/PDB:"C:\LProj\vs\cppconMariaDB02\Debug\cppconMariaDB02.pdb" 
/DYNAMICBASE "c:\L\SQLClient\mariadb_client-1.0.0-win64\lib\libmariadb.lib" 
"c:\L\SQLClient\mariadb_client-1.0.0-win64\lib\mariadbclient.lib" 
"kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib"
"shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG 
/MACHINE:X86 /INCREMENTAL /PGD:"C:\LProj\vs\cppconMariaDB02\Debug\cppconMariaDB02.pgd"
/SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'"
/ManifestFile:"Debug\cppconMariaDB02.exe.intermediate.manifest" 
/ERRORREPORT:PROMPT /NOLOGO 
/LIBPATH:"C:\L\SQLClient\mariadb_client-1.0.0-win64\lib" 
/TLBID:1 

I've been stuck for a full week on this unresolved external symbol _mysql_init@4 error, and not making any progress, despite numerous searches on the web and many trials.

If someone could be kind enough to point me the right way to link to libraries,I would be sooo grateful !

It's most certainly a simple option, but I can't see any other place where I can write paths or references.

Thank's in advance for your time.

Olivier

Was it helpful?

Solution

Make sure your project and the library match in terms of 32 bit/ 64 bit. I made a 32 bit console app in VS2013 and using your sample and downloading the 64 bit library. I got the same error. Then I made the console app 64 bits and no longer had an error.

Here is how to target x64: http://msdn.microsoft.com/en-us/library/9yb4317s(v=vs.110).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top