Unresolved symbol while using a matlab function turned into a shared library - c++

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

Related

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

error MSB3073: :VCEnd" exited with code 2

I Know this problem been posted and I search the internet looking for the solution of my problem. I am new to programming and I try to find the answer before posting my problem.
I am trying to do a code interface node for Labview. Follow the direction and of course search on the internet. I setup my environment variables to point where my files are at. I set up the property page and were I am having the trouble at is on the command line in the custom build set up. I enter the following command:
"$(CINTOOLSDIR)\lvsbutil" "$(TargetName)" -d "$(OutDir)"
and for the Output I enter
$(OutDir) $(TargetName).lsb.
`
when I build the code I get the following.
'
Project: SimpleCIN2010, Configuration: Release Win32 ------
1>C:\Program Files(x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(298,5): warning MSB8004: Intermediate Directory does not end with a trailing slash. This build instance will add the slash as it is required to allow proper evaluation of the Intermediate Directory.
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(299,5): warning MSB8004: Output Directory does not end with a trailing slash. This build instance will add the slash as it is required to allow proper evaluation of the Output Directory.
1> SimpleCIN2010.cpp
1> Microsoft (R) Incremental Linker Version 10.00.40219.01
1> Copyright (C) Microsoft Corporation. All rights reserved.
1>
1> "/OUT:.\Release\SimpleCIN2010.dll" /INCREMENTAL "/LIBPATH:C:\Program Files (x86)\National Instruments\LabVIEW 8.6\cintools" cin.obj labview.lib lvsb.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:C:\Program Files (x86)\National Instruments\LabVIEW 8.6\cintools\lvsbmain.def" /MANIFEST "/ManifestFile:.\Release\SimpleCIN2010.dll.intermediate.manifest" "/MANIFESTUAC:level='asInvoker' uiAccess='false'" /DEBUG "/PDB:C:\Users\XXX\Documents\Visual Studio 2010\Projects\CIN VC2010\SimpleCIN2010\SimpleCIN2010\Release\SimpleCIN2010.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /TLBID:1 /DYNAMICBASE /NXCOMPAT "/IMPLIB:.\Release\SimpleCIN2010.lib" /MACHINE:X86 /DLL .\Release\SimpleCIN2010.dll.embed.manifest.res
1> .\Release\SimpleCIN2010.obj
1>LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/OPT:ICF' specification
1>SimpleCIN2010.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specification
1> Creating library .\Release\SimpleCIN2010.lib and object .\Release\SimpleCIN2010.exp
1> Microsoft (R) Incremental Linker Version 10.00.40219.01
1> Copyright (C) Microsoft Corporation. All rights reserved.
1>
1> "/OUT:.\Release\SimpleCIN2010.dll" /INCREMENTAL "/LIBPATH:C:\Program Files (x86)\National Instruments\LabVIEW 8.6\cintools" cin.obj labview.lib lvsb.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:C:\Program Files (x86)\National Instruments\LabVIEW 8.6\cintools\lvsbmain.def" /MANIFEST "/ManifestFile:.\Release\SimpleCIN2010.dll.intermediate.manifest" "/MANIFESTUAC:level='asInvoker' uiAccess='false'" /DEBUG "/PDB:C:\Users\XXX\Documents\Visual Studio 2010\Projects\CIN VC2010\SimpleCIN2010\SimpleCIN2010\Release\SimpleCIN2010.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /TLBID:1 /DYNAMICBASE /NXCOMPAT "/IMPLIB:.\Release\SimpleCIN2010.lib" /MACHINE:X86 /DLL .\Release\SimpleCIN2010.dll.embed.manifest.res
1> .\Release\SimpleCIN2010.obj
1>LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/OPT:ICF' specification
1>SimpleCIN2010.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specification
1> Creating library .\Release\SimpleCIN2010.lib and object .\Release\SimpleCIN2010.exp
1> SimpleCIN2010.vcxproj -> C:\Users\XXXX\Documents\Visual Studio 2010\Projects\CIN VC2010\SimpleCIN2010\SimpleCIN2010\.\Release\SimpleCIN2010.dll
1> C:\Program Files (x86)\National Instruments\LabVIEW 8.6\cintools\lvsbutil: error building resource file: 1
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(183,5): error MSB3073: The command ""C:\Program Files (x86)\National Instruments\LabVIEW 8.6\cintools\lvsbutil" "SimpleCIN2010" -d ".\Release\"
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(183,5): error MSB3073: :VCEnd" exited with code 2.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========`
I went into the command line to double check for double spacing or not enough. I read the other article that been posted and try some of the codes. So if someone could tell me if I set up the command right please let me know.
Thanks
I finally found out that the issue was from trying to use two different version software. After over a week and many hours on the internet searching for an answer I came across an article on how to make the lsb file. First I had to remove the custom build commands and output from the property manager. rebuild the program to create my release folder under my project. once this was done i follow the following steps:
Executing cmd.exe When Compiling a CIN in VC++
You can reduce the introduction of typing errors and mis-quoting by following these steps:
1. Go to the start button and click run. Then type cmd in the command window and hit enter.
Browse to the directory that has lvsbutil.exe (in the cintools directory under LabVIEW), drag the lvsbutil.exe onto the cmd window. This will correctly quote the executable.
Browse to the folder that holds your dll, this is usually in /Debug of your project's directory, verify that a dll has been created there.
In the cmd window, type the following command: project_name -d
Drag the folder that contains the dll onto the cmd window, and press enter.
You should see LabVIEW resource file with the following properties created properly:
type: CIN
name: sharedcin.lsb
The .lsb file will be built in the same directory as the DLL.
Note: LabVIEW must be installed on the computer that the VC++ code is compiled on. Simply copying the cintools directory to the computer that will compile your code without having LabVIEW installed will cause an error when linking.

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.

Linker Error Building GDAL

I am building GDAL from source using the MSVC 2015 64-bit command prompt. I am using Windows 8. Part way through the build, I get the following error:
Creating library gdal_i.lib and object gdal_i.exp
odbccp32.lib(dllload.obj) : error LNK2019: unresolved external symbol _vsnwprintf_s referenced in function StringCchPrintfW
gdal201.dll : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\link.EXE"' : return code '0x460'
Stop.
I have read on the Microsoft Site and GDAL Git issues section that this was a problem with the 2014 MSVC and pre-release version of MSVC 2015, but the issue was supposed to be resolved prior to the final release of MSVC 2015.
https://github.com/mapbox/windows-builds/issues/53
https://connect.microsoft.com/VisualStudio/feedback/details/1134693/vs-2015-ctp-5-c-vsnwprintf-s-and-other-functions-are-not-exported-in-appcrt140-dll-breaking-linkage-of-static-libraries
I don't seem to be the only person with this issue, but I am also not seeing a solution (besides reverting to an older version of MSVC such as 2013). Has anybody had any luck getting GDAL to build using MSVC 2015 (64 bit)?
GDAL-2.1.0 already has a similar change on nmake.opt
!IFDEF ODBC_SUPPORTED
!IF $(MSVC_VER) >= 1900
# legacy_stdio_definitions.lib : https://connect.microsoft.com/VisualStudio/feedback/details/1134693/vs-2015-ctp-5-c-vsnwprintf-s-and-other-functions-are-not-exported-in-appcrt140-dll-breaking-linkage-of-static-libraries
ODBCLIB = legacy_stdio_definitions.lib odbc32.lib odbccp32.lib user32.lib
!ELSE
ODBCLIB = odbc32.lib odbccp32.lib user32.lib
!ENDIF
!ENDIF
but you must also specify the Visual Studio version from the command line with parameter MSVC_VER.
e.g. for Visual Studio 2015 (MSVC_VER==1900) use this command line to compile
nmake -f makefile.vc MSVC_VER=1900
I edited nmake.opt:
I replaced line 667 ... :
!IFDEF ODBC_SUPPORTED
ODBCLIB = odbc32.lib odbccp32.lib user32.lib
!ENDIF
with:
!IFDEF ODBC_SUPPORTED
!IF $(MSVC_VER) < 1900
ODBCLIB = odbc32.lib odbccp32.lib user32.lib
!ELSE
ODBCLIB = legacy_stdio_definitions.lib odbc32.lib odbccp32.lib user32.lib
!ENDIF
!ENDIF
/Anders
In addition to the above, I also had to make the following modification to the nmake.opt file:
the line that says
!IFNDEF MSVC_VER
#assume msvc VS2008.
MSVC_VER=1500
!ENDIF
Should be changed to:
!IFNDEF MSVC_VER
#assume msvc VS2015.
MSVC_VER=1900
!ENDIF

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