Unresolved external symbol in MIDL COM library - c++

My system is a Windows 10 64-bit fall creators edition with Visual Studio 2010 Professional.
I have a COM interface with the following IDL (ISomeInterface.idl):
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(61E246F6-3F22-404B-8EA8-E4D13F3206D6),
pointer_default(unique)
]
interface ISomeInterface : IUnknown
{
HRESULT DoSomething();
}
[
uuid(7EF22D33-5C29-4D32-BFBC-0B276C5F7427),
version(1.0),
helpstring("ISomeInterface 1.0 Type Library")
]
library ISomeInterfaceLib
{
importlib("stdole2.tlb");
[
uuid(BC91D238-B0E1-4FA2-AAC8-195D761DF9DC),
version(1.0),
helpstring("ISomeInterface Class")
]
coclass ISomeInterfaceImpl
{
[default] interface ISomeInterface;
};
};
Which I compile with this command:
midl /iid "ISomeInterface_i.c" /env win32 /h "ISomeInterface.h" /W1 /char signed /tlb "Release\ISomeInterface.tlb" /Oicf /D "NDEBUG" /robust /nologo /proxy "ISomeInterface_p.c" ISomeInterface.idl
Then I create a module definition file (ISomeInterface.def):
LIBRARY "ISomeInterface"
EXPORTS
DllGetClassObject PRIVATE
DllCanUnloadNow PRIVATE
DllRegisterServer PRIVATE
DllUnregisterServer PRIVATE
IID_ISomeInterface DATA
LIBID_ISomeInterfaceLib DATA
And I build my interface DLL using these commands:
cl /c /Zi /W1 /WX- /O2 /Oy- /D WIN32 /D REGISTER_PROXY_DLL /D NDEBUG /D _WINDLL /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Release\\" /Fd"Release\vc100.pdb" /Gd /TC /analyze- /errorReport:prompt dlldata.c ISomeInterface_i.c ISomeInterface_p.c
link "/OUT:Release\ISomeInterface.dll" rpcns4.lib rpcrt4.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 "/DEF:ISomeInterface.def" /MANIFEST "/ManifestFile:Release\ISomeInterface.dll.intermediate.manifest" "/MANIFESTUAC:level='asInvoker' uiAccess='false'" "/PDB:Release\ISomeInterface.pdb" /OPT:REF /OPT:ICF /TLBID:1 /DYNAMICBASE /NXCOMPAT "/IMPLIB:Release\ISomeInterface.lib" /MACHINE:X86 /DLL Release\dlldata.obj Release\ISomeInterface_i.obj Release\ISomeInterface_p.obj
My issue is that when I create my ATL executable it keeps failing to link giving me this:
SomeApp.obj : error LNK2001: unresolved external symbol _LIBID_ISomeInterfaceLib
I am using #include "ISomeInterface.h" and have added ISomeInterface.lib to Linker->Input.
Running dumpbin.exe /exports Release\ISomeInterface.dll provides the following:
Microsoft (R) COFF/PE Dumper Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file Release\ISomeInterface.dll
File Type: DLL
Section contains the following exports for ISomeInterface.dll
00000000 characteristics
5ABD61A2 time date stamp Thu Mar 29 17:58:58 2018
0.00 version
1 ordinal base
6 number of functions
6 number of names
ordinal hint RVA name
1 0 00001040 DllCanUnloadNow
2 1 00001000 DllGetClassObject
3 2 000010A0 DllRegisterServer
4 3 000010E0 DllUnregisterServer
5 4 000030E8 IID_ISomeInterface
6 5 000030F8 LIBID_ISomeInterfaceLib
Summary
1000 .data
1000 .orpc
1000 .rdata
1000 .reloc
1000 .text
Running dumpbin.exe -headers Release\ISomeInterface.lib | findstr /c:" Symbol name :" shows that the symbol in in the LIB file:
Symbol name : _IID_ISomeInterface
Symbol name : _LIBID_ISomeInterfaceLib
If I use the ISomeInterface_i.c in the project and remove the LIB then it compiles fine, but I am attempting to get away from that...

So if I delete DATA from the module definition file the symbols link correctly it seems. new file:
LIBRARY "ISomeInterface"
EXPORTS
DllGetClassObject PRIVATE
DllCanUnloadNow PRIVATE
DllRegisterServer PRIVATE
DllUnregisterServer PRIVATE
IID_ISomeInterface
LIBID_ISomeInterfaceLib

Related

Very slow VS2017 C++ linker speed

We're upgrading our C++ projects from VS2013 to VS2017. But in VS2017 we have very bad linking times also for Debug builds. With such values, it's not possible to do effective development.
When I change the single file in our project, in VS2013 it takes 2.6sec. When I do the same with the same file in VS2017 it takes 30sec.
VS2013
1> 32 ms ComputeCLOutputs 1 calls
1> 199 ms WarnCompileDuplicatedFilename 1 calls
1> 2688 ms Link 1 calls
1> 4073 ms ClCompile 1 calls
VS2017
1> 31 ms ComputeCLOutputs 1 calls
1> 44 ms CustomBuild 1 calls
1> 239 ms WarnCompileDuplicatedFilename 1 calls
1> 8021 ms ClCompile 1 calls
1> 29725 ms Link 1 calls
This is more than 15x slower than in VS2013.
Currently, I have both Visual Studios installed on my PC so I can test it side-by-side. I tried a lot of things as same as a lot of googling but without success.
I tried:
compile the same project in VS2017 but with VS2013 toolset and linking takes 2.6sec. So the problem is with toolset in VS2017 not with VS2017 IDE.
I tried a lot of combinations with DebugInformationFormat like /Zi and /Z7, as same as /DEBUG vs /DEBUG:Fastlink, /INCREMENTAL,... but any other settings is even worse than default one generated by QMake (/Zi + /DEBUG:Fastlink + /INCREMENTAL).
I also tried 32bit and 64bit compiler/linker as same as 32/64bit target. But it doesn't have any impact on performance.
I tried to convert VS2013 project to VS2017 as same as generating new one via Qt Qmake but also without any differences.
During link time CPU isn't used at 100% as same as SSD drive isn't utilized at 100%. I tried to output verbose linking log but there isn't anything special (no foreign temporary files, etc. like mentioned in other answers).
This is complete compiler command line
/Yu"stdafx.h" /MP /GS /analyze- /W3 /wd"4577" /wd"4467" /Zc:wchar_t /I ...INCLUDE FOLDERS... /Zi /Gm- /Od /Fd"objs\Debug32\" /FI"stdafx.h" /fp:precise
/D "_WINDOWS" /D "UNICODE" /D "WIN32" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /MDd /Fa"objs\Debug32\" /EHsc /nologo /Fo"objs\Debug32\"
/Fp"Debug32\\App.pch" /diagnostics:classic
-Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zm130 -w44996 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458
And linker command line
/OUT:"Debug32\\App.exe" /MANIFEST /NXCOMPAT /PDB:"Debug32\App.pdb" /DYNAMICBASE "Q:\SharedLibraries2017\Qt32\lib\qtmaind.lib" "shell32.lib" ...
/VERSION:"1.0" /DEBUG /MACHINE:X86 /SAFESEH /INCREMENTAL /PGD:"Debug32\App.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:"level='asInvoker' uiAccess='false'"
/ManifestFile:"_App\objs\Debug32\App.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"Q:\SharedLibraries2017\Qt32\lib" /TLBID:1
"/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'"
I found few some posts about slow linking but nothing helped for me (64bit, erasing temporary files, turning of synchro/sourcurce control/codelens/diagnostic, clean build in new folders, ... ).
I'm using latest VS2017 version 15.5.6, toolset v141, SDK 10.0.16299.0
Any help will be appreciated.
Added:
My PC setup is:
i7-7700K CPU # 4.2Ghz
16GB Ram
SSD Drive
Latest Win10
Edited:
I tried another (smaller) project.
When I do complete rebuild, I got these results:
VS2013:
1> 2898 ms Link 1 calls
1> 11987 ms CustomBuild 1 calls
1> 68238 ms ClCompile 1 calls
VS2017
1> 2822 ms Link 1 calls
1> 14221 ms CustomBuild 1 calls
1> 67243 ms ClCompile 1 calls
So almost identical results. But, when I change for example main.cpp in both projects and do compilation+link, I got this:
VS2013:
1> 577 ms Link 1 calls
1> 1261 ms ClCompile 1 calls
VS2017
1> 1196 ms ClCompile 1 calls
1> 3145 ms Link 1 calls
So, the problem seems to be that no mather how many files are linked together, in VS2017 the time is still the same.
Edit2:
Based on #seccur idea I installed also VS2015 toolkit
Again, two same projects, both fully compiled & linked and in both I moddified main.cpp file.
VS2015 (2015 v140)
1> 64 ms WarnCompileDuplicatedFilename 1 calls
1> 594 ms Link 1 calls
1> 1312 ms ClCompile 1 calls
VS2017 (2017 v141)
1> 43 ms WarnCompileDuplicatedFilename 1 calls
1> 754 ms ClCompile 1 calls
1> 2082 ms Link 1 calls
Both projects opened in VS2017 IDE, both with same settings, the only difference is toolkit selection. It's more than clear that v141 toolkit is completely bugged.

When resolving a symlink with boost the result doesn't equal the original path name

Windows 10
MS VS 2015
C++11
Boost 1.60
I create this symbolic link:
mklink /J "C:\T4 2.0\ApplicationSymlinks\T4" "C:\T4 2.0\Data"
This is a much simplified version of a program to check if the symbolic link is linked to the proper directory:
#include <boost/filesystem.hpp>
#include <iostream>
int main()
{
boost::filesystem::path directory = "c:\\T4 2.0\\Data";
boost::filesystem::path symlink = "c:\\T4 2.0\\ApplicationSymlinks\\T4";
boost::filesystem::path path_linked_to("");
path_linked_to = boost::filesystem::read_symlink(symlink); // Resolve symlink. path_linked_to is not absolute. L"\\T4 2.0\\Data"
path_linked_to = boost::filesystem::absolute(path_linked_to); // Absolute path. L"c:\\T4 2.0\\Data"
if (directory == path_linked_to)
std::cout << "paths are equal" << std::endl;
else
std::cout << "paths are not equal" << std::endl;
return 0;
}
The output is "paths are not equal". Shouldn't they be equal? In the autos window of the debugger I do see this:
directory size 14 capacity 15
where as
path_linked_to size 16 capacity 23 because it includes two trailing '\0's.
These two trailing '\0's are introduced in read_symlink.
How do I resolve this? Why doesn't read_symlink return an absolute? Why does read_symlink add in two trailing '\0's (assuming that is the problem)? Why does operator== not ignore the '\0's?
How I compiled and linked:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\CL.exe /c /IC:\Libraries\boost_1_60_0 /ZI /nologo /W3 /WX- /sdl /Od /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"x64\Debug\\" /Fd"x64\Debug\vc140.pdb" /Gd /TP /errorReport:prompt resolvesymlilnk.cpp stdafx.cpp
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\link.exe /ERRORREPORT:PROMPT /OUT:"c:\Users\Therefore\Documents\Visual Studio 2015\Projects\resolvesymlilnk\x64\Debug\resolvesymlilnk.exe" /INCREMENTAL /NOLOGO /LIBPATH:"C:\Libraries\boost_1_60_0\lib64-msvc-14.0" kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /Debug /PDB:"c:\Users\Therefore\Documents\Visual Studio 2015\Projects\resolvesymlilnk\x64\Debug\resolvesymlilnk.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"c:\Users\Therefore\Documents\Visual Studio 2015\Projects\resolvesymlilnk\x64\Debug\resolvesymlilnk.lib" /MACHINE:X64 x64\Debug\resolvesymlilnk.obj
This is a known bug in Boost: https://svn.boost.org/trac/boost/ticket/10900
Unfortunately it hasn't been fixed yet and has been assigned a low priority, so if you want it fixed you're going to have to do it yourself.
The problem is that when boost.filesystem reads the REPARSE_DATA_BUFFER structure, it assumes that the reparse is a symbolic link so always uses the SymbolicLinkReparseBuffer union member; for a junction it should use MountPointReparseBuffer. This means that the buffer calculations are sizeof(ULONG) off and so the read path is missing the drive letter and colon (L"C:") and has two wide characters added at the end instead, which as you've observed are usually null characters. (The wide characters get converted to narrow characters on the way out of the boost.filesystem internals.)
The fix would be in read_symlink to check whether the ReparseTag member is IO_REPARSE_TAG_SYMLINK or IO_REPARSE_TAG_MOUNT_POINT (as in is_reparse_point_a_symlink), and use SymbolicLinkReparseBuffer or MountPointReparseBuffer respectively. As the ticket linked above says, Boost should really use SubstituteNameOffset/SubstituteNameLength instead of PrintNameOffset/PrintNameLength and strip the leading L"\??\" for absolute symlinks and for junctions.

Unresolved symbol while using a matlab function turned into a shared library

I'm using MATLAB R2012A and Visual Studio 2013.
I have a simple function in a simulation.m file.
function [ r ] = simulation( )
r = 42;
end
Since VS2013 is not supported by MATLAB 2012 I've setup my version of VS in MATLAB using these files.
I've then built the corresponding dll using:
>> mcc -v -W lib:libsim -T link:lib simulation.m
Compiler version: 4.17 (R2012a)
Processing C:\Program Files\MATLAB\R2012a\toolbox\matlab\mcc.enc
Processing include files...
2 item(s) added.
Processing directories installed with MCR...
The file mccExcludedFiles.log contains a list of functions excluded from the CTF archive.
1 item(s) added.
Generating MATLAB path for the compiled application...
Created 41 path items.
Begin validation of MEX files: Wed Apr 15 13:55:43 2015
End validation of MEX files: Wed Apr 15 13:55:43 2015
Parsing file "C:\Users\aaptel\Documents\MATLAB\simulation.m"
(Referenced from: "Compiler Command Line").
Parsing file "C:\Program Files\MATLAB\R2012a\toolbox\compiler\deploy\deployprint.m"
(Referenced from: "Compiler Command Line").
Parsing file "C:\Program Files\MATLAB\R2012a\toolbox\compiler\deploy\printdlg.m"
(Referenced from: "Compiler Command Line").
Deleting 0 temporary MEX authorization files.
Generating file "libsim.h".
Generating file "libsim.c".
Generating file "libsim.exports".
Generating file "C:\Users\aaptel\Documents\MATLAB\readme.txt".
Executing command: ""C:\Program Files\MATLAB\R2012a\bin\mbuild" -O -v -output "libsim" "libsim.c" "libsim.exports" -link shared"-> Default options filename found in C:\Users\aaptel\AppData\Roaming\MathWorks\MATLAB\R2012a
----------------------------------------------------------------
-> Options file = C:\Users\aaptel\AppData\Roaming\MathWorks\MATLAB\R2012a\compopts.bat
-> COMPILER = cl
-> Compiler flags:
COMPFLAGS = -MD -c -Zp8 -GR -EHsc- -Zc:wchar_t- -W3 -nologo -I"C:\PROGRA~1\MATLAB\R2012a\extern\include\win64" -DMSVC -DIBMPC /D_CRT_SECURE_NO_DEPRECATE
OPTIMFLAGS = -O2 -DNDEBUG
DEBUGFLAGS = -Z7
arguments =
Name switch = /Fo
-> Pre-linking commands =
-> LINKER = link
-> Link directives:
LINKFLAGS = /MACHINE:AMD64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /LIBPATH:"C:\PROGRA~1\MATLAB\R2012a\extern\lib\win64\microsoft" /nologo /manifest /manifestfile:"libsim.msvc.manifest" mclmcrrt.lib /dll /implib:"libsim.lib" /def:"C:\Users\aaptel\AppData\Local\Temp\mbuild_F85T7Q\templib.def"
LINKFLAGSPOST =
Name directive = /out:"libsim.dll"
File link directive =
Lib. link directive =
Rsp file indicator = #
-> Resource Compiler = rc /fo ".res"
-> Resource Linker =
----------------------------------------------------------------
--> cl -MD -c -Zp8 -GR -EHsc- -Zc:wchar_t- -W3 -nologo -I"C:\PROGRA~1\MATLAB\R2012a\extern\include\win64" -DMSVC -DIBMPC /D_CRT_SECURE_NO_DEPRECATE /FoC:\Users\aaptel\AppData\Local\Temp\mbuild_F85T7Q\libsim.obj -IC:\PROGRA~1\MATLAB\R2012a\extern\include -IC:\PROGRA~1\MATLAB\R2012a\simulink\include -O2 -DNDEBUG libsim.c
libsim.c
--> type C:\Users\aaptel\AppData\Local\Temp\mbuild_F85T7Q\mbuild_tmp.exports | "C:\PROGRA~1\MATLAB\R2012a\sys\perl\win32\bin\perl.exe" -e "print \"LIBRARY libsim.dll\nEXPORTS\n\"; while (<>) {print;}" > "C:\Users\aaptel\AppData\Local\Temp\mbuild_F85T7Q\templib.def"
Contents of C:\Users\aaptel\AppData\Local\Temp\mbuild_F85T7Q\mbuild_tmp.rsp:
C:\Users\aaptel\AppData\Local\Temp\mbuild_F85T7Q\libsim.obj
--> link /out:"libsim.dll" /MACHINE:AMD64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /LIBPATH:"C:\PROGRA~1\MATLAB\R2012a\extern\lib\win64\microsoft" /nologo /manifest /manifestfile:"libsim.msvc.manifest" mclmcrrt.lib /dll /implib:"libsim.lib" /def:"C:\Users\aaptel\AppData\Local\Temp\mbuild_F85T7Q\templib.def" #C:\Users\aaptel\AppData\Local\Temp\mbuild_F85T7Q\mbuild_tmp.rsp
Création de la bibliothèque libsim.lib et de l'objet libsim.exp
--> "if exist C:\Users\aaptel\AppData\Local\Temp\mbuild_F85T7Q\templib.def del C:\Users\aaptel\AppData\Local\Temp\mbuild_F85T7Q\templib.def"
--> mt.exe -outputresource:"libsim.dll";2 -manifest "libsim.msvc.manifest"
Microsoft (R) Manifest Tool version 6.3.9600.17298
Copyright (c) Microsoft Corporation 2012.
All rights reserved.
--> del "libsim.msvc.manifest"
I now have the following files:
libsim.dll
libsum.exp
libsim.c
libsim.exports
libsim.h
I've installed the 64bit MATLAB runtime for MATLAB R2012a.
I've created a new C++ solution in VS and added the libsim.lib dependency, along with the matlab lib/include dir.
Here is my main cpp file:
#include <cstdio>
#include <libsim.h>
int main(void)
{
double v = 42;
libsimInitialize();
printf("%d\n", v);
libsimTerminate();
return 0;
}
The compiler flags:
/GS /analyze- /W3 /Zc:wchar_t /I"C:\Users\aaptel\Documents\Visual Studio 2013\Projects\CppTest\CppTest\Include\matlab" /ZI /Gm /Od /sdl /Fd"Debug\vc120.pdb" /fp:precise /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\CppTest.pch"
The linker flags:
/OUT:"C:\Users\aaptel\Documents\Visual Studio 2013\Projects\CppTest\Debug\CppTest.exe" /MANIFEST /NXCOMPAT /PDB:"C:\Users\aaptel\Documents\Visual Studio 2013\Projects\CppTest\Debug\CppTest.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" "libsim.lib" /DEBUG /MACHINE:X86 /INCREMENTAL /PGD:"C:\Users\aaptel\Documents\Visual Studio 2013\Projects\CppTest\Debug\CppTest.pgd" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\CppTest.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:\Users\aaptel\Documents\Visual Studio 2013\Projects\CppTest\CppTest\Lib\matlab" /TLBID:1
libsim.lib is in there, the Lib\matlab and Include\matlab paths have a copy of the matlab runtime libs and headers.
But. it. doesn't. freaking. compile.
1>Source.obj : error LNK2019: symbole externe non résolu _libsimInitialize référencé dans la fonction _main
1>Source.obj : error LNK2019: symbole externe non résolu _libsimTerminate référencé dans la fonction _main
1>C:\Users\aaptel\Documents\Visual Studio 2013\Projects\CppTest\Debug\CppTest.exe : fatal error LNK1120: 2 externes non résolus
Notice how the compiler looks for the symbol prefixed with an underscore. If you look at the symbol in the lib file using DUMPBIN you can see that they don't have the prefix (full DUMPBIN output):
Dump of file libsim.lib
File Type: LIBRARY
Archive member name at 8: /
552CE345 time/date Tue Apr 14 11:52:05 2015
uid
gid
0 mode
190 size
correct header end
15 public symbols
3AA __IMPORT_DESCRIPTOR_libsim
5D0 __NULL_IMPORT_DESCRIPTOR
706 libsim_NULL_THUNK_DATA
85E __imp_libsimInitialize
85E libsimInitialize
8CA __imp_libsimInitializeWithHandlers
8CA libsimInitializeWithHandlers
9B4 __imp_libsimTerminate
9B4 libsimTerminate
942 __imp_libsimPrintStackTrace
942 libsimPrintStackTrace
A8A __imp_mlxSimulation
A8A mlxSimulation
A20 __imp_mlfSimulation
A20 mlfSimulation
Why doesn't it work and how do I call my matlab function from C++?
OK, turns out the VS project was 32bit but the lib/dll generated by MATLAB was 64bit. By switching the VS project to x64, it compiled.
VS seems to silently ignore linking 32bit executable against 64bits libs
Also see follow-up post on the mathworks QA site:
http://www.mathworks.com/matlabcentral/answers/203699-how-do-i-call-standalone-matlab-shared-library-built-with-mcc-from-c

Visual Studio 2012 - C MariaDB Client - Error LNK2019: unresolved external symbol _mysql_init#4

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
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

Visual Studio 2010 - Linking MySQL

I gave myself a project to get familiar with Windows Programming and Visual Studio. I am having trouble linking to the MySQL libraries so that I can use it in my project. I keep getting a LNK2019 error, which most likely means that I am not linking the .lib files properly. I've already set its configuration to include the include directories and library directories. (I also tried different combinations of setting VC++ Directories and C/C++ / Linker.)
Error 1 error LNK2019: unresolved external symbol _mysql_real_connect#32 referenced in function "public: void __thiscall Database::connect_db(void)" (?connect_db#Database##QAEXXZ) D:\Media\Documents\Visual Studio 2010\Projects\swtPrice Server\swtPrice Server\Database.obj
Error 2 error LNK2019: unresolved external symbol _mysql_init#4 referenced in function "public: void __thiscall Database::connect_db(void)" (?connect_db#Database##QAEXXZ) D:\Media\Documents\Visual Studio 2010\Projects\swtPrice Server\swtPrice Server\Database.obj
Error 3 error LNK1120: 2 unresolved externals D:\Media\Documents\Visual Studio 2010\Projects\swtPrice Server\Debug\swtPrice Server.exe 1
Here is a snippet of code that I copied online and trying to compile:
MYSQL *connection, mysql;
MYSQL_RES *result;
MYSQL_ROW row;
int query_state;
mysql_init(&mysql);
//connection = mysql_real_connect(&mysql,"host","user","password","database",0,0,0);
connection = mysql_real_connect(&mysql,"localhost","bainm","not_telling","cpp_data",0,0,0);
if (connection == NULL) {
//cout << mysql_error(&mysql) << endl;
//return 1;
}
I configured my project to include the MySQL's include directory. This is how it looks like in the command line under the C/C++ tab:
/I"D:\Program Files\MySQL\MySQL Server 5.5\include" /ZI /nologo /W1 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yu"StdAfx.h" /Fp"Debug\swtPrice Server.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /analyze- /errorReport:queue
I configured my to include the MySQL's Library directory. This is how it looks like in the command line under the Linker:
/OUT:"D:\Media\Documents\Visual Studio 2010\Projects\swtPrice Server\Debug\swtPrice Server.exe" /NOLOGO /LIBPATH:"D:\Program Files\MySQL\MySQL Server 5.5\lib" "D:\Program Files\MySQL\MySQL Server 5.5\lib\libmysql.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" /MANIFEST /ManifestFile:"Debug\swtPrice Server.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"D:\Media\Documents\Visual Studio 2010\Projects\swtPrice Server\Debug\swtPrice Server.pdb" /SUBSYSTEM:CONSOLE /PGD:"D:\Media\Documents\Visual Studio 2010\Projects\swtPrice Server\Debug\swtPrice Server.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE
This is how the mySQL library directory looks like:
Directory of D:\Program Files\MySQL\MySQL Server 5.5\lib
05/06/2011 10:38 AM <DIR> .
05/06/2011 10:38 AM <DIR> ..
05/06/2011 10:38 AM <DIR> debug
03/31/2011 04:53 PM 4,177,408 libmysql.dll
03/31/2011 04:53 PM 23,920 libmysql.lib
03/31/2011 04:52 PM 10,625,266 mysqlclient.lib
05/06/2011 10:38 AM <DIR> plugin
Any help is appreciated. Thank you in advance for any help.
I ran in to the same problem of being getting link errors for all of the mysql api functions in VisualStudio2010. I confirmed the problem was due to using a 32-bit target in Visual Studio with a 64-bit build of MySQL. I added an x64 build to my build configuration and it linked without any errors