Linker Error Building GDAL - c++

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

Related

CMake build showing VS compiler error: cl.exe - broken and LINK error: cannot open 'kernel32.lib'

I've been trying to build some code using CMake via PowerShell(administrator).
I've run Microsoft Visual Studio 10.0\VC\vcvarsall.bat for setting environment variables.
I also set every environment variable required for this project (for CMake, BUILD_ROOT, etc).
Also, I've windows SDK version 8.0 and 8.1 in the system.
But, when I try to compile, I get a compiler broken error and a 'kernel32.lib' missing error, even though 'kernel32.lib' is there in the windows SDK path.
Can anyone provide me with a possible solution, please?
Attaching the PowerShell Output below:
> PS > C:\project\build-dir> cmake ..
> -DBUILD_CLASSIFIER=Windows-x64-VS100 -DCMAKE_BUILD_TYPE=Release -G "NMake Makefiles" $env:BUILD_ROOT\3rd_Party\lib-6.5.1
-- The C compiler identification is MSVC 16.0.30319.1
-- The CXX compiler identification is MSVC 16.0.30319.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/cl.exe - broken CMake Error at C:/Program
Files/CMake/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69
(message): The C compiler
"C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/build-dir/CMakeFiles/CMakeTmp
Run Build Command(s):nmake -f Makefile /nologo cmTC_cefcc\fast && "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\nmake.exe"
-f CMakeFiles\cmTC_cefcc.dir\build.make /nologo -L CMakeFiles\cmTC_cefcc.dir\bu ild
Building C object CMakeFiles/cmTC_cefcc.dir/testCCompiler.c.obj
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_cl_compile_depends --dep-file=CMakeFiles\cmTC_cefcc.dir\testCCom
piler.c.obj.d
--working-dir=C:\GITWS\CP.24.0_dev_New\print_server\CMService\colorToolKit\ctk-build\CMakeFiles\CMakeTmp -
-filter-prefix="Note: including file: " -- C:\PROGRA~2\MICROS~4.0\VC\bin\cl.exe
#C:\Users\ADMINI~1.XER\AppData\Local\Tem p\nm8FBD.tmp
testCCompiler.c
Linking C executable cmTC_cefcc.exe
"C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_cefcc.dir --rc=C:\PROGRA~2\MICROS ~1\Windows\v7.0A\Bin\RC.Exe
--mt=C:\PROGRA~2\MICROS~1\Windows\v7.0A\Bin\mt.exe --manifests -- C:\PROGRA~2\MICROS~4.0\VC\ bin\link.exe /nologo
#CMakeFiles\cmTC_cefcc.dir\objects1.rsp
#C:\Users\ADMINI~1.XER\AppData\Local\Temp\nm904A.tmp
LINK Pass 1: command "C:\PROGRA~2\MICROS~4.0\VC\bin\link.exe /nologo #CMakeFiles\cmTC_cefcc.dir\objects1.rsp /out:cm TC_cefcc.exe
/implib:cmTC_cefcc.lib
/pdb:C:\GITWS\CP.24.0_dev_New\print_server\CMService\colorToolKit\ctk-build\CMakeFil
es\CMakeTmp\cmTC_cefcc.pdb /version:0.0 /machine:X86 /debug
/INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi3
2.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFi
les\cmTC_cefcc.dir/intermediate.manifest
CMakeFiles\cmTC_cefcc.dir/manifest.res" failed (exit code 1104) with
the follow ing output:
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
NMAKE : fatal error U1077: '"C:\Program Files\CMake\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\nmake.exe"' : return code '0 x2'
Stop.
CMake will not be able to correctly generate this project. Call
Stack (most recent call first): CMakeLists.txt:4 (PROJECT)
-- Configuring incomplete, errors occurred! See also "C:/project/build-dir/CMakeFiles/CMakeOutput.log". See also
"C:/project/build-dir/CMakeFiles/CMakeError.log".

CMake & GitHub Actions - Windows build of CMake library on GitHub Actions not linking library to test suite

I have an open source CMake project that runs perfectly well on Linux. However, to make it more portable, I decided to add in Windows build options. To test this, I set up the GitHub Actions CMake Based Applications, and set the conditions to build on ubuntu-latest, windows-latest, and macos-latest.
My workflow file is as follows:
name: CMake
on: [push]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team#latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout#v2
- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
run: cmake -E make_directory ${{github.workspace}}/build
- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
working-directory: ${{github.workspace}}/build
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
- name: Build
working-directory: ${{github.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE
- name: Test
working-directory: ${{github.workspace}}/build
shell: bash
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C $BUILD_TYPE
It's pretty standard and works fine. The problem arrives when I try to build on Windows, and only Windows. To add portability to Windows, I added this to my CMakeLists.txt:
if(WIN32)
set(FETCHCONTENT_BASE_DIR "C:/Users/$ENV{USERNAME}/AppData/Local/Temp")
endif()
This worked perfectly to keep my fetched dependencies outside of the source directory (CMake would complain). But when I tried to build with Windows, the library would get built fine but couldn't be found to be linked with the testing suite (Catch2 + CTest).
Link:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\link.exe /ERRORREPORT:QUEUE /OUT:"D:\a\libeztp\libeztp\build\tests\Release\tests.exe" /INCREMENTAL:NO /NOLOGO ..\Release\libeztp.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /PDB:"D:/a/libeztp/libeztp/build/tests/Release/tests.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"D:/a/libeztp/libeztp/build/tests/Release/tests.lib" /MACHINE:X64 /machine:x64 tests.dir\Release\mainTest.obj
LINK : fatal error LNK1181: cannot open input file '..\Release\libeztp.lib' [D:\a\libeztp\libeztp\build\tests\tests.vcxproj]
Done Building Project "D:\a\libeztp\libeztp\build\tests\tests.vcxproj" (default targets) -- FAILED.
Done Building Project "D:\a\libeztp\libeztp\build\ALL_BUILD.vcxproj" (default targets) -- FAILED.
Build FAILED
...
D:\a\libeztp\libeztp\build\ALL_BUILD.vcxproj" (default target) (1) ->
"D:\a\libeztp\libeztp\build\tests\tests.vcxproj" (default target) (5) ->
(Link target) ->
LINK : fatal error LNK1181: cannot open input file '..\Release\libeztp.lib' [D:\a\libeztp\libeztp\build\tests\tests.vcxproj]
I was pulling my hair out, and found this SO post that seemed to have a somewhat related problem. So to my CMakeLists.txt, I changed the Windows if to:
if(WIN32)
set(FETCHCONTENT_BASE_DIR "C:/Users/$ENV{USERNAME}/AppData/Local/Temp")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) # I did try commenting out this line, but it was the same error from before.
set(BUILD_SHARED_LIBS TRUE)
endif()
Now the library was linking properly (or so it seems), but now it couldn't find some exported symbols.
Link:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\link.exe /ERRORREPORT:QUEUE /OUT:"D:\a\libeztp\libeztp\build\tests\Release\tests.exe" /INCREMENTAL:NO /NOLOGO ..\Release\libeztp.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /PDB:"D:/a/libeztp/libeztp/build/tests/Release/tests.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"D:/a/libeztp/libeztp/build/tests/Release/tests.lib" /MACHINE:X64 /machine:x64 tests.dir\Release\mainTest.obj
mainTest.obj : error LNK2019: unresolved external symbol "class std::map<int,class eztp::Die,struct std::less<int>,class std::allocator<struct std::pair<int const ,class eztp::Die> > > eztp::dice" (?dice#eztp##3V?$map#HVDie#eztp##U?$less#H#std##V?$allocator#U?$pair#$$CBHVDie#eztp###std###4##std##A) referenced in function "void __cdecl ____C_A_T_C_H____T_E_S_T____0(void)" (?____C_A_T_C_H____T_E_S_T____0##YAXXZ) [D:\a\libeztp\libeztp\build\tests\tests.vcxproj]
D:\a\libeztp\libeztp\build\tests\Release\tests.exe : fatal error LNK1120: 1 unresolved externals [D:\a\libeztp\libeztp\build\tests\tests.vcxproj]
Done Building Project "D:\a\libeztp\libeztp\build\tests\tests.vcxproj" (default targets) -- FAILED.
Done Building Project "D:\a\libeztp\libeztp\build\ALL_BUILD.vcxproj" (default targets) -- FAILED.
...
"D:\a\libeztp\libeztp\build\ALL_BUILD.vcxproj" (default target) (1) ->
"D:\a\libeztp\libeztp\build\tests\tests.vcxproj" (default target) (5) ->
(Link target) ->
mainTest.obj : error LNK2019: unresolved external symbol "class std::map<int,class eztp::Die,struct std::less<int>,class std::allocator<struct std::pair<int const ,class eztp::Die> > > eztp::dice" (?dice#eztp##3V?$map#HVDie#eztp##U?$less#H#std##V?$allocator#U?$pair#$$CBHVDie#eztp###std###4##std##A) referenced in function "void __cdecl ____C_A_T_C_H____T_E_S_T____0(void)" (?____C_A_T_C_H____T_E_S_T____0##YAXXZ) [D:\a\libeztp\libeztp\build\tests\tests.vcxproj]
D:\a\libeztp\libeztp\build\tests\Release\tests.exe : fatal error LNK1120: 1 unresolved externals [D:\a\libeztp\libeztp\build\tests\tests.vcxproj]
At this point, I'm exhausted and just want this to be over, as I haven't plan on developing on Windows for quite some time. Could someone point me in the right direction and help me figure out what I'm missing? I'm just throwing stuff at a wall at this point and hoping something sticks.
Edit:
Here is the implementation of the exported symbol:
dice.hpp
namespace eztp {
class Die {
//Implementation probably irrelevant
};
extern std::map<int, Die> dice;
}
dice.cpp
std::map<int, eztp::Die> eztp::dice = {
{0, eztp::Die(0)},
{1, eztp::Die(1)},
{2, eztp::Die(2)},
{4, eztp::Die(4)},
{6, eztp::Die(6)},
{8, eztp::Die(8)},
{10, eztp::Die(10)},
{12, eztp::Die(12)},
{20, eztp::Die(20)},
{100, eztp::Die(100)}
};

Build error with "___report_rangecheckfailure" with OpenSSL libs

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

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

How to build SHTTPD on Windows?

I tried building SHTTPD on Windows using the following command:
nmake msvc Makefile
All i get is a bunch of errors. What am I doing wrong?
Microsoft (R) Program Maintenance Utility Version 10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved. cl /MD /TC /nologo /DNDEBUG /Os standalone.c /link /out:shttpd.exe ws2_32.lib user32.lib advapi32.lib shell32.lib shttpd.lib standalone.c c:\users\samira\desktop\network\shttpd-1.42\src\compat_win32.h(46) : warning C4005: 'EWOULDBLOCK' : macro redefinition C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\errno.h(132) : see previous definition of 'EWOULDBLOCK' –
According to the site you link, you have to use the command
nmake win
to build on windows.
Edit From the site you linked:
Download the source package. Extract
it, go to src directory. Run "make
unix" there ("nmake win" on Windows,
requires MSVC). That buillds a
library.
Have you invoked the command from the src directory?