Compiling C++/CX on the command line - visual-c++

I get the linker error fatal error C1107: could not find assembly 'platform.winmd': please specify the assembly search path using /AI or by setting the LIBPATH environment variable when I try to compile a C++/CX program on the command line.
The error is the same after I followed the instructions on this page: https://msdn.microsoft.com/en-us/library/dn769142.aspx (to summarize: run cl /ZW /EHsc source.cpp from the Developer Command Prompt for VS2015)
I also tried running vcvarsall.bat x86 store from the Developer Command Prompt for VS2015 but I still get the same error (the same error also happens when running vcvarsall.bat x86 store from a plain command prompt).

UPDATE: Apparently this bug has been fixed in VS2015 Update 1, I have not been able to test myself yet though.
As it turns out some command line parameters are missing from the documentation mentioned in the question, here is the full command line required to compile a small program:
cl /ZW
/ZW:nostdlib
/D WINAPI_FAMILY=WINAPI_FAMILY_APP
/D __WRL_NO_DEFAULT_LIB__
/Gm-
/EHsc
/MDd
/FU"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\store\references\platform.winmd"
/FU"C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.FoundationContract\1.0.0.0\Windows.Foundation.FoundationContract.winmd"
/FU"C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.UniversalApiContract\1.0.0.0\Windows.Foundation.UniversalApiContract.winmd"
smurf.cpp
/link /SUBSYSTEM:CONSOLE
Where smurf.cpp contains:
using namespace Platform;
int main(Platform::Array<Platform::String^>^ args)
{
Platform::Details::Console::WriteLine("This is a C++/CX program.");
}
Will successfully print:
C:\Users\Mikael>smurf.exe
This is a C++/CX program.

Related

LNK1104 error with python setup.py build

I have built Quantlib on Windows using Visual Studio 2017 and want to build Quantlib-SWIG for Python.
However, I have LNK1104: error. Namely, after launching Command Prompt from C:\QuantLib-SWIG-1.12\Python directory I receive this error:
fatal error LNK1104: cannot open file 'QuantLib-vc90-x64-mt.lib'
I saw a similar question with advise from Luigi Ballabio and KingJohnno to verify if QuantLib-vc90-x64-mt.lib file is in place & add to the path variable C:\QuantLib-SWIG-1.12.
I did the last suggestion, but I have the problem with that I have in C:\QuantLib\QuantLib-1.12\lib a QuantLib-vc141-x64-mt.lib library, i.e. not the file QuantLib-vc90-x64-mt.lib. I have created separate directory with vc141 file renamed to vc90. This did not help.
I have also read online that the problem might be with the Python specifically builded using different VS version. I have downloaded Python 2.7 builded using VS 2010 (not VS2008) and did not succeed as well.
Please see the whole terminal message here:
C:\QuantLib-SWIG-1.12\Python>cd C:\QuantLib-SWIG-1.12\Python
C:\QuantLib-SWIG-1.12\Python>set QL_DIR=C:\QuantLib\QuantLib-1.12
C:\QuantLib-SWIG-1.12\Python>set INCLUDE=C:\Boost\boost_1_66_0
C:\QuantLib-SWIG-1.12\Python>
C:\QuantLib-SWIG-1.12\Python>python setup.py build
running build
running build_py
running build_ext
building 'QuantLib._QuantLib' extension
C:\Users\user1\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -D__WIN32__ -DWIN32 -DNDEBUG -D_WINDOWS -DNOMINMAX -IC:\Python27vc08\include -IC:\Python27vc08\PC -IC:\QuantLib\QuantLib-1.12 -IC:\Boost\boost_1_66_0 /TpQuantLib/quantlib_wrap.cpp /Fobuild\temp.win-amd64-2.7\Release\QuantLib/quantlib_wrap.obj /GR /FD /Zm250 /EHsc /bigobj /MD
quantlib_wrap.cpp
C:\Users\user1\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\xutility(2472) : warning C4267: '=' : conversion from 'size_t' to 'unsigned int', possible loss of data
C:\Users\user1\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\xutility(2485) : see reference to function template instantiation '_OutIt std::_Copy_opt<_InIt,unsigned int*,std::forward_iterator_tag>(_InIt,_InIt,_OutIt,_InOutItCat,std::_Nonscalar_ptr_iterator_tag,std::_Range_checked_iterator_tag)' being compiled
with
[
_OutIt=unsigned int *,
_InIt=const unsigned __int64 *,
_InOutItCat=std::forward_iterator_tag
]
C:\Users\user1\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\xutility(2563) : see reference to function template instantiation '_OutIt std::_Copy_opt<const unsigned __int64*,_OutIt>(_InIt,_InIt,_OutIt,std::random_access_iterator_tag,std::_Nonscalar_ptr_iterator_tag,std::_Range_checked_iterator_tag)' being compiled
with
[
_OutIt=std::_Vector_iterator<std::_Vbase,std::allocator<std::_Vbase>>,
_InIt=const unsigned __int64 *
]
QuantLib/quantlib_wrap.cpp(16340) : see reference to function template instantiation 'std::_Vector_iterator<_Ty,_Alloc> std::copy<std::_Vector_const_iterator<unsigned __int64,std::allocator<unsigned __int64>>,std::_Vector_iterator<_Ty,_Alloc>>(_InIt,_InIt,_OutIt)' being compiled
with
[
_Ty=std::_Vbase,
_Alloc=std::allocator<std::_Vbase>,
_InIt=std::_Vector_const_iterator<size_t,std::allocator<size_t>>,
_OutIt=std::_Vector_iterator<std::_Vbase,std::allocator<std::_Vbase>>
]
C:\Users\user1\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python27vc08\libs /LIBPATH:C:\Python27vc08\PCbuild\amd64 /LIBPATH:C:\Python27vc08\PC\VS9.0\amd64 /LIBPATH:C:\QuantLib\QuantLib-1.12\lib /EXPORT:init_QuantLib build\temp.win-amd64-2.7\Release\QuantLib/quantlib_wrap.obj /OUT:build\lib.win-amd64-2.7\QuantLib\_QuantLib.pyd /IMPLIB:build\temp.win-amd64-2.7\Release\QuantLib\_QuantLib.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\QuantLib\_QuantLib.pyd.manifest /subsystem:windows /machine:x64
LINK : fatal error LNK1104: cannot open file 'QuantLib-vc90-x64-mt.lib'
error: command 'C:\\Users\\user1\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\link.exe' failed with exit status 1104
C:\QuantLib-SWIG-1.12\Python>
python setup.py build worked under Python 3.6.5.

MSVC2017 compiler error, Chromium build fails

So I am on:
Windows 10
MS Visual Studio 2017 (2017 build tools)
trying to build:
qt5.10.1 with QtWebEngine
using jom.exe -j4
and during the QtWebEngine build process, this happened:
[51/12427] CC obj/third_party/webrtc/common_audio/common_audio_c/sqrt_of_one_minus_x_squared.obj
[52/12427] CC obj/third_party/webrtc/common_audio/common_audio_c/complex_fft.obj
[53/12427] CXX obj/third_party/webrtc/call/call/call.obj
FAILED: obj/third_party/webrtc/call/call/call.obj
ninja -t msvc -e environment.x64 -- "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX64\x64/cl.exe" /nologo /showIncludes #obj/third_party/webrtc/call/call/call.obj.rsp /c ../../3rdparty/chromium/third_party/webrtc/call/call.cc /Foobj/third_party/webrtc/call/call/call.obj /Fd"obj/third_party/webrtc/call/call_cc.pdb"
C:\Qt\qt-everywhere-src-5.10.1\qtwebengine\src\3rdparty\chromium\third_party\webrtc/modules/video_coding/sequence_number_util.h(101): fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'f:\dd\vctools\compiler\cxxfe\sl\p1\c\outdname.c', line 5310)
To work around this problem, try simplifying or changing the program near the locations listed above.
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\xutility(301): note: see reference to class template instantiation 'webrtc::DescendingSeqNumComp<uint16_t,0>' being compiled
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\xutility(301): note: see reference to variable template 'const bool is_empty_v<webrtc::DescendingSeqNumComp<unsigned short,0> >' being compiled
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\xtree(1078): note: see reference to class template instantiation 'std::_Tree_comp_alloc<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<uint16_t,webrtc::NackModule::NackInfo,webrtc::DescendingSeqNumComp<uint16_t,0>,std::allocator<std::pair<const uint16_t,webrtc::NackModule::NackInfo>>,false>
]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include\map(82): note: see reference to class template instantiation 'std::_Tree<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,false>>' being compiled
with
[
_Kty=uint16_t,
_Ty=webrtc::NackModule::NackInfo,
_Pr=webrtc::DescendingSeqNumComp<uint16_t,0>,
_Alloc=std::allocator<std::pair<const uint16_t,webrtc::NackModule::NackInfo>>
]
C:\Qt\qt-everywhere-src-5.10.1\qtwebengine\src\3rdparty\chromium\third_party\webrtc/modules/video_coding/nack_module.h(88): note: see reference to class template instantiation 'std::map<uint16_t,webrtc::NackModule::NackInfo,webrtc::DescendingSeqNumComp<uint16_t,0>,std::allocator<std::pair<const _Kty,_Ty>>>' being compiled
with
[
_Kty=uint16_t,
_Ty=webrtc::NackModule::NackInfo
]
[54/12427] CC obj/third_party/webrtc/common_audio/common_audio_c/refl_coef_to_lpc.obj
[55/12427] CC obj/third_party/webrtc/common_audio/common_audio_c/vector_scaling_operations.obj
[56/12427] CC obj/third_party/webrtc/common_audio/common_audio_c/spl_sqrt_floor.obj
[57/12427] CC obj/third_party/webrtc/common_audio/common_audio_c/resample_by_2.obj
[58/12427] CC obj/third_party/webrtc/common_audio/common_audio_c/webrtc_vad.obj
[59/12427] CC obj/third_party/webrtc/common_audio/common_audio_c/spl_init.obj
[60/12427] CXX obj/third_party/webrtc/common_audio/common_audio/sparse_fir_filter.obj
[61/12427] CXX obj/third_party/webrtc/common_audio/common_audio/real_fourier_ooura.obj
[62/12427] CXX obj/third_party/webrtc/common_audio/common_audio_cc/dot_product_with_scale.obj
ninja: build stopped: subcommand failed.
jom: C:\Qt\qt-everywhere-src-5.10.1\qtwebengine\src\core\Makefile.gn_run.Debug [run_ninja] Error 1
jom: C:\Qt\qt-everywhere-src-5.10.1\qtwebengine\src\core\Makefile.gn_run [debug-all] Error 2
jom: C:\Qt\qt-everywhere-src-5.10.1\qtwebengine\src\core\Makefile [sub-gn_run-pro-make_first] Error 2
jom: C:\Qt\qt-everywhere-src-5.10.1\qtwebengine\src\Makefile [sub-core-make_first] Error 2
jom: C:\Qt\qt-everywhere-src-5.10.1\qtwebengine\Makefile [sub-src-make_first] Error 2
jom: C:\Qt\qt-everywhere-src-5.10.1\Makefile [module-qtwebengine-make_first] Error 2
C:\Qt\qt-everywhere-src-5.10.1>
I found this forum with a slightly active/recent question asking about this same issue here:
Internal compiler error in outdname.c in VS15.7p3 when building Firefox webrtc code
Is there anything I can do from this point to fix this?
Downgrading my version of VS to 2015 allowed me to bypass this compiler error and compile QT successfully.

Custom media effect in Win10 Universal App

I'm developing an Universal Windows App that uses the camera and I need to create a custom effect for the camera. The app is written in C# and the effect is a C++ DLL that uses Media Foundation and an IDL to define a custom WinRT component.
I already successfully do this several times on Windows 8.1 with the following trick documented here, or here.
I now want to port this on Windows 10 UWP. I'm aware there is a known issue on Windows 10 which make the compiler fail with the error "Failed to load a dependency file. Windows.winmd" (see here). But even with that fix, I'm not able to successfully build the component.
Here is the IDL:
import "Windows.Media.idl";
#include <sdkddkver.h>
namespace MyEffect
{
[version(NTDDI_WIN10), activatable(NTDDI_WIN10)]
runtimeclass MyEffect
{
[default] interface Windows.Media.IMediaExtension;
}
}
The MIDL command line (formatted for better readability):
/env win32 /h "MyEffect_h.h" /W1 /char signed /enum_class
/tlb "$(OutDir)\MyEffect.tlb" /ns_prefix
/metadata_dir "$(WindowsSDK_MetadataFoundationPath)"
/nologo /winrt
/winmd "$(OutDir)\MyEffect.winmd"
This command succeeds. Then I add the following custom build step:
mdmerge -metadata_dir “<metadata_dir>”
-i “$(OutDir).”
-o “$(OutDir)merged”
-partial
-v
and this command fails always with different errors according to the following :
If I put $(WindowsSDK_MetadataFoundationPath), which resolves to c:\Program Files (x86)\Windows Kits\10\References\windows.foundation.foundationcontract\1.0.0.0, or $(WindowsSDK_MetadataPath), which resolves to c:\Program Files (x86)\Windows Kits\10\References it returns the error:
MDMERGE : error MDM2002: The type "Windows.Media.IMediaExtension" defined in file <...>\MyEffect.winmd was referenced by type MyEffect.MyEffect but could not be found.
If I put $(TargetPlatformSdkMetadataLocation), which resolves to c:\Program Files (x86)\Windows Kits\10\References\CommonConfiguration\Neutral, it returns the error:
MDMERGE : error MDM2012: Error 3 has occured while enumerating files in C:\Program Files (x86)\Windows Kits\10\References\CommonConfiguration\Neutral\*.winmd.
Does anyone figured out how to compile a custom Windows Media effect for UWP ?
Setting -metadata_dir to "C:\Program Files (x86)\Windows Kits\10\UnionMetadata" worked for me.

how to compile in vc++ without .dsw workspace file?

I downloaded a source code from codeproject.com
In the zip file only .cpp files and .hpp files were present but no .dsw (vc++ work space) file.
how to compile the files in vc++.
source code link: http://www.codeproject.com/Articles/13852/BasicExcel-A-Class-to-Read-and-Write-to-Microsoft
As far as I know, vc++ requires a dsw. That said, you can easily create one by creating a project + workspace and add import all the files into the project.
Unless the code requires special compile options (unlikely if it comes without a project file), this should work fine.
When you compile in VisualC++ cl.exe is executed in order to compile a s program.
So a way to compile that does not require dsw file might be running compilation in command line. This is an example for a source file main.cpp:
call vsvars32.bat && cl /MD /Od /EHsc /GR /Zi /Oy- main.cpp
On my computer the full path to vsvars32.bat is
C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat
dsw is an ancient format, and is replaced by .sln and .vcxproj files. What I would suggest would be File -> New -> Project from existing code, browse to the directory with the cpp/hpp files and let Visual Studio create the project with default compiler switches - so you won't have to run cl.exe from the command line as suggested here.
That being said, the chances of circa-2006 c++ code to work on IDEs 4 versions later are small. You will almost certainly have to understand and fix the code - or find a more recent one that does what you need.

Error LNK1104: cannot open file 'python27.lib' PyISAPIe

Am trying to compile a 64bit version of PyISAPIe using VS2010. Am not used to C/C++ programming but managed to configure some settings for VS2010. Everything went well until it got to the linking stage where it gave the above mentioned error. I checked all the Library path settings and they looked fine. Below is my command line for building the DLL:
/OUT:"x64\Release\PyISAPIe.dll" /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\pyisapie\Python\x64\Python27\libs" /LIBPATH:"C:\pyisapie\Python\x64\Python26\libs" /LIBPATH:"C:\pyisapie\Python\x64\Python25\libs" /DLL "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /NODEFAULTLIB:"libc libcmt msvcrt" /DEF:"PyISAPIe.def" /MANIFEST /ManifestFile:"x64\Release\PyISAPIe.dll.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /PDB:"C:\pyisapie\x64\Release\PyISAPIe.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /PGD:"C:\pyisapie\x64\Release\PyISAPIe.pgd" /LTCG /TLBID:1 /DYNAMICBASE:NO /IMPLIB:"x64\Release\PyISAPIe.lib" /MACHINE:X64 /ERRORREPORT:QUEUE
The path C:\pyisapie\Python\x64\Python27\libs exists and containes python27.lib.
Can anyone help me out. Thanks in advance
I just compared your linker command line to mine (I'm the project author) and it's exactly the same as far as flags go, so you might want to look into other reasons why the file can't be opened. Is it an x64 lib for sure? Do you have access?
You might try reinstalling the newest 2.7 x64 release into a different location and add that folder instead.
I had the same issue due to not setting the LIBPATH correctly. This may not be the cause of your error message, but it was the cause of mine.
To resolve it in Visual Studio right click on the PyISAPIe project and select:
Properties > Configuration Properties > Linker > General
Then make sure that the path C:\pyisapie\Python\x64\Python27\libs (or the relative path) is listed in the "Additional Library Directories"

Resources