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
Related
I built the last available version of the library (5.6.5) wanting to use it in a Qt msvc project. The issue is, that the linker want's for some reason the cryptopp.lib that is produced when building the fips dll.
This is my config (only the relevant):
INCLUDEPATH += $$PWD/thirdparty/Win/cryptopp/include
LIBS += -L$$PWD/thirdparty/Win/cryptopp/debug/ -lcryptlib
The compiler output:
LINK : fatal error LNK1104: cannot open file 'cryptopp.lib'
EDIT:
The link command + the result: Which the result is the same as above.
link /NOLOGO /DYNAMICBASE /NXCOMPAT /NODEFAULTLIB:MSVCRT /DEBUG /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:debug\QtTrafficBrowser.exe #C:\Users\Mij\AppData\Local\Temp\QtTrafficBrowser.exe.1316.6203.jom
LINK : fatal error LNK1104: cannot open file 'cryptopp.lib'
jom: C:\Users\Mij\qt_creator\qtTrafficBrowser\build-QtTrafficBrowser-Desktop_Qt_5_8_0_MSVC2015_32bit-Debug\Makefile.Debug [debug\QtTrafficBrowser.exe] Error 1104
jom: C:\Users\Mij\qt_creator\qtTrafficBrowser\build-QtTrafficBrowser-Desktop_Qt_5_8_0_MSVC2015_32bit-Debug\Makefile [debug] Error 2
I am not trying to use the DLL!! I know it's different and I knew it from the start so stop asking me not to use it. The problem is that when linking with cryptlib.lib the linker asks for cryptopp.lib also. Is it clear?
I was dumb.
I added the dll.h into my project, that's why it was asking for the cryptopp.lib.
Removed it, and boom, works.
People having a similar issue, look at this also. LNK1104 Cryptopp.lib with CRYPTOPP_DEFAULT_NO_DLL defined in dll project
I am trying to compile 5.6.2. I have already compiled OpenSSL. nmake ran for about half an hour and then I get this error: (using quotes because they line-break which IMO improves readability; not sure if language is an issue here; if yes, I might translate certain lines...)
cl -c -nologo -Zc:wchar_t -FS -Zc:strictStrings -Zi -MTd -MP -W3 -w44456 -w44457 -w44458 /Fd.obj\debug\qwebpd.vc.pdb -DUNICODE -DWIN32 -DQT_NO_EXCEPTIONS -DQT_STATICPLUGIN -DQT_PLUGIN -DQT_GUI_LIB -DQT_CORE_LIB -I. -I......\3rdparty\libwebp -I......\3rdparty\libwebp\src -I......\3rdparty\libwebp\src\dec -I......\3rdparty\libwebp\src\enc -I......\3rdparty\libwebp\src\dsp -I......\3rdparty\libwebp\src\mux -I......\3rdparty\libwebp\src\utils -I......\3rdparty\libwebp\src\webp -IC:\Users\Michael\Documents\vs13\Projects\Telegram\build\Libraries\qt5_6_2\qtbase\include
-IC:\Users\Michael\Documents\vs13\Projects\Telegram\build\Libraries\qt5_6_2\qtbase\include\QtGui
-IC:\Users\Michael\Documents\vs13\Projects\Telegram\build\Libraries\qt5_6_2\qtbase\include\QtCore
-I.moc\debug -IC:\Users\Michael\Documents\vs13\Projects\Telegram\build\Libraries\openssl\Release\include
-IC:\Users\Michael\Documents\vs13\Projects\Telegram\build\Libraries\qt5_6_2\qtbase\mkspecs\win32-msvc2015
-Fo.obj\debug\Users\Michael\Documents\vs13\Projects\Telegram\build\Libraries\qt5_6_2\qtimageformats\src\3rdparty\libwebp\src\dsp\upsampling_sse2.obj
......\3rdparty\libwebp\src\dsp\upsampling_sse2.c
upsampling_sse2.c
C:\Users\Michael\Documents\vs13\Projects\Telegram\build\Libraries\qt5_6_2\qtimageformats\src\3rdparty\libwebp\src\dsp\upsampling_sse2.c
: fatal error C1083: Datei (vom Compiler generiert) kann nicht
geöffnet werden: "": Invalid argument
NMAKE : fatal error U1077: ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.EXE"": Rückgabe-Code "0x1"
Stop.
NMAKE : fatal error U1077: ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\nmake.EXE"": Rückgabe-Code "0x2"
Stop.
NMAKE : fatal error U1077: "cd": Rückgabe-Code "0x2"
Stop.
NMAKE : fatal error U1077: "cd": Rückgabe-Code "0x2"
Stop.
NMAKE : fatal error U1077: "cd": Rückgabe-Code "0x2"
Stop.
NMAKE : fatal error U1077: "cd": Rückgabe-Code "0x2"
Stop.
NMAKE : fatal error U1077: "cd": Rückgabe-Code "0x2"
Stop.
I have created the makefile before with:
configure -debug-and-release -force-debug-info -opensource
-confirm-license -static -I "C:\Users\Michael\Documents\vs13\Projects\Telegram\build\Libraries\openssl\Release\include"
-L "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib" -l Gdi32 -no-opengl -openssl-linked OPENSSL_LIBS_DEBUG="C:\Users\Michael\Documents\vs13\Projects\Telegram\build\Libraries\openssl_debug\Debug\lib\ssleay32.lib
C:\Users\Michael\Documents\vs13\Projects\Telegram\build\Libraries\openssl_debug\Debug\lib\libeay32.lib"
OPENSSL_LIBS_RELEASE="C:\Users\Michael\Documents\vs13\Projects\Telegram\build\Libraries\openssl\Release\lib\ssleay32.lib
C:\Users\Michael\Documents\vs13\Projects\Telegram\build\Libraries\openssl\Release\lib\libeay32.lib"
-mp -nomake examples -nomake tests -platform win32-msvc2015
Any idea what could we wrong here? What I could even check? I just do not understand this error message.
I could solve the issue...
The windows path was too long. I created a junction directory to not be forced to move all files to other paths.
being in C:\Users\Michael I typed in the cmd:
mklink /J /D tgqt C:\Users\Michael\Documents\vs13\Projects\Telegram\build\Libraries\qt5_6_2
After cd tgqt I have just built from that directory et voilà...
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
Using VC++ 2010
Compiling with OpenSSL libraries to make a SHA512 hash...
getting this build error:
1>------ Build started: Project: Second, Configuration: Debug Win32 ------
1> stdafx.cpp
1> AssemblyInfo.cpp
1>Second.cpp
1> Second.cpp(64): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\stdio.h(371) : see declaration of 'sprintf'
1> Generating Code...
1> .NETFramework,Version=v4.0.AssemblyAttributes.cpp
1> Microsoft (R) Incremental Linker Version 10.00.40219.01
1> Copyright (C) Microsoft Corporation. All rights reserved.
1>
1> "/OUT:C:\Users\Boss\documents\visual studio 2010\Projects\Second\Debug\Second.exe" /INCREMENTAL "C:\Program Files\OpenSSL-Win32\lib\VC\static\ssleay32MD.lib" "C:\Program Files\OpenSSL-Win32\lib\VC\static\libeay32MD.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 /ASSEMBLYRESOURCE:Debug\Second.Form1.resources /MANIFEST "/ManifestFile:Debug\Second.exe.intermediate.manifest" "/MANIFESTUAC:level='asInvoker' uiAccess='false'" /DEBUG "/PDB:C:\Users\Boss\documents\visual studio 2010\Projects\Second\Debug\Second.pdb" /ASSEMBLYDEBUG /SUBSYSTEM:WINDOWS /TLBID:1 "/ENTRY:main" /DYNAMICBASE /FIXED:NO /NXCOMPAT /MACHINE:X86 Debug\app.res
1> Debug\AssemblyInfo.obj
1> Debug\Second.obj
1> Debug\stdafx.obj
1> "Debug\.NETFramework,Version=v4.0.AssemblyAttributes.obj"
1>libeay32MD.lib(obj_dat.obj) : error LNK2019: unresolved external symbol ___report_rangecheckfailure referenced in function _OBJ_create_objects
1>libeay32MD.lib(b_print.obj) : error LNK2001: unresolved external symbol ___report_rangecheckfailure
1>C:\Users\Boss\documents\visual studio 2010\Projects\Second\Debug\Second.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Tried disabling buffer overrun security check, same error..
Any thoughts? Tried all day with Crypto++, to no avail, OpenSSL was much easier, just hung up on this one error...
It looks as though you are trying to link to OpenSSL libraries that were built with a later version of the compiler.
Function ___report_rangecheckfailure was introduced in more recent versions of Visual Studio (see http://blogs.microsoft.com/cybertrust/2012/01/26/enhancements-to-gs-in-visual-studio-11/ for details).
So the linker is looking in the VS2010 libraries to find a function that didn't exist until later.
The maintainer of at least one of the pre-built OpenSSL libraries for Windows has recently switched from using an earlier version of Visual Studio, which may be the trigger for your problems.
One solution is to build your own OpenSSL Windows binaries with VS2010 (See http://developer.covenanteyes.com/building-openssl-for-visual-studio/ for example).
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