Visual Studio 2010 - Linking MySQL - c++

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

Related

Detection of icu libs fails with VS2017

I'm building Qt 5.11.1 from sources with VS2017 build tools.
The environment I set is as follows:
set QTDIR=%CD%
set PATH=%PATH%;%QTDIR%\qtbase\bin;C:\Oracle11\client11.2.0\bin;C:\Python27\;C:\ruby_2.0.0\bin;C:\Python27\Scripts\;C:\Perl64\site\bin;C:\Perl64\bin;C:\GnuWin32\bin;C:\icu\bin64
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars64.bat"
set INCLUDE=%INCLUDE%;C:\app\client\x\product\12.2.0\client_1\oci\include;C:\Python27\include;C:\ruby_2.0.0\include;"C:\mysql-5.5\include;C:\icu\include";"C:\Program Files (x86)\Windows Kits\10\Include"
set LIB=%LIB%;C:\app\client\x\product\12.2.0\client_1\oci\lib\msvc;C:\Python27\Lib;C:\ruby_2.0.0\lib;"C:\mysql-5.5\lib";C:\icu\lib64;"C:\Program Files (x86)\Windows Kits\10\Lib"
then call the configure script:
configure -prefix %QTDIR%\_STAGE -platform win32-msvc -commercial -confirm-license -release -shared -qt-libjpeg -qt-libpng -no-cups -no-mtdev -nomake examples -icu -plugin-sql-mysql -plugin-sql-odbc -plugin-sql-sqlite -opengl dynamic -skip qtconnectivity -skip webengine -D _IGNORE_FINAL
The script does some work, and when checking the configurations, it fails - cannot find icu:
ERROR: Feature 'icu' was enabled, but the pre-condition 'libs.icu' failed.
Check config.log for details.
Here's the relevant part from config.log:
loaded result for library config.qtbase_corelib.libraries.icu
Trying source 0 (type inline) of library icu ...
=> source failed condition 'config.win32 && !features.shared'.
Trying source 1 (type inline) of library icu ...
+ cd /d C:\Users\x\Documents\qt\config.tests\icu && C:\Users\x\Documents\qt\qtbase\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "DEFINES += _IGNORE_FINAL" "LIBS += -licuin -licuuc -licudt" C:/Users/x/Documents/qt/config.tests/icu
+ cd /d C:\Users\x\Documents\qt\config.tests\icu && set MAKEFLAGS=& nmake
> Microsoft (R) Program Maintenance Utility Version 14.15.26726.0
> Copyright (C) Microsoft Corporation. All rights reserved.
> cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -O2 -MD -W0 -EHsc -DUNICODE -D_UNICODE -DWIN32 -DWIN64 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_IGNORE_FINAL -DNDEBUG -I. -IC:\Users\x\Documents\qt\qtbase\mkspecs\win32-msvc -Fo #C:\Users\x\AppData\Local\Temp\8\nm8F4F.tmp
> main.cpp
> link /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:icu.exe #C:\Users\x\AppData\Local\Temp\8\nm91F0.tmp
> main.obj : error LNK2019: unresolved external symbol ucol_open_57 referenced in function main
> main.obj : error LNK2019: unresolved external symbol ucol_close_57 referenced in function main
> icu.exe : fatal error LNK1120: 2 unresolved externals
> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\link.EXE"' : return code '0x460'
> Stop.
I tried to build the standalone main.cpp from config.tests\icu with
cl main.cpp /EHsc
and got the same linker error. Then I added the libs path and the libs and the build succeeded:
cl main.cpp /EHsc /link /LIBPATH:C:\icu\lib64 icudt.lib icuin.lib icuio.lib icule.lib iculx.lib icutu.lib icuuc.lib
But when I added the libs to configure script, got the same linker error.
Any idea what I'm doing wrong or missing?
try to move icu lib path to the first and re-configure seems solve the problem
set lib=D:\Qt\Qt5.11.1\third-party\icu-lib\lib;%lib%
test Qt5.11.1 in VS2017 5.8.4 32bit
D:\Qt\Qt5.11.1>cd D:\Qt\Qt5.11.1\5.11\msvc2017build\config.tests\icu
D:\Qt\Qt5.11.1\5.11\msvc2017build\config.tests\icu>set lib
LIB=D:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\ATLMFC\lib\x86;D:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\lib\x86;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x86;C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\ucrt\x86;C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86;;D:\Qt\Qt5.11.1\third-party\icu-lib\lib;D:\Qt\Qt5.11.1\third-party\openssl-lib\lib
LIBPATH=D:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\ATLMFC\lib\x86;D:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\lib\x86;D:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\lib\x86\store\references;C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.17134.0;C:\Program Files (x86)\Windows Kits\10\References\10.0.17134.0;C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319;
D:\Qt\Qt5.11.1\5.11\msvc2017build\config.tests\icu>nmake
Microsoft (R) Program Maintenance Utility Version 14.15.26729.0
Copyright (C) Microsoft Corporation. All rights reserved.
link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:icu.exe #C:\Users\harry\AppData\Local\Temp\nm8ACC.tmp
LINK : icu.exe not found or not built by the last incremental link; performing full link
main.obj : error LNK2019: unresolved external symbol _ucol_open_62 referenced in function _main
main.obj : error LNK2019: unresolved external symbol _ucol_close_62 referenced in function _main
icu.exe : fatal error LNK1120: 2 unresolved externals
NMAKE : fatal error U1077: '"D:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\bin\HostX86\x86\link.EXE"' : return code '0x460'
Stop.
D:\Qt\Qt5.11.1\5.11\msvc2017build\config.tests\icu>set lib=D:\Qt\Qt5.11.1\third-party\icu-lib\lib;%lib%
D:\Qt\Qt5.11.1\5.11\msvc2017build\config.tests\icu>nmake
Microsoft (R) Program Maintenance Utility Version 14.15.26729.0
Copyright (C) Microsoft Corporation. All rights reserved.
link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:icu.exe #C:\Users\harry\AppData\Local\Temp\nmA818.tmp

Unresolved external symbol in MIDL COM library

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

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