Can not build assembly code in visual studio - visual-studio

For some reason, I have to use some assembly code in my dll library project. My visual studio version is 2019.
I follow the settings as below to build assembly code
Project -> Build customizations, check masm
In the property of my assembly code file, set Item Type to Microsoft Macro Assembler
Then I build the project and got the following error.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations\masm.targets(70,5): error MSB3721: The command "ml64.exe /c /nologo /Zi /Fo"x64\Debug\my_assembly.obj" /W3 /errorReport:prompt /Tamy_assembly.asm" exited with code 1.
But if I go to my project directory and run ml64.exe with options in error message above, I can successfully build the assembly code.
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\Hostx64\x64\ml64.exe" /c /nologo /Zi /Fo"x64\Debug\my_assembly.obj" /W3 /errorReport:prompt /Tamy_assembly.asm
Assembling: my_assembly.asm
After the manual build of my_assembly.obj from commandline, the build also succeed in visual studio IDE.
What's wrong with the ml64.exe invoked from visual studio IDE?

Related

Visual Studio 2022: error MSB3721: The command "ml.exe ... " exited with code 1

I am using Microsoft Visual Studio Community 2022 (ARM 64-bit) Version 17.3.0 Preview 6.0 to build a Win32 (Intel x86 32-bit) application. I get the following error:
1>C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Microsoft\VC\v170\BuildCustomizations\masm.targets(70,5): error MSB3721: The command "ml.exe /c /nologo /Sg /Zi /Fo"Debug\byteasm.obj" /D"_DEBUG" /Fl"Debug\byteasm.lst" /W3 /errorReport:prompt /TaC:\Users\James\Documents\Dolphin\Core\DolphinVM\VMLib..\byteasm.asm" exited with code 1.
But when I open a command prompt I can successfully execute the following:
"C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.33.31629\bin\Hostx86\x86\ml.exe" /c /nologo /Sg /Zi /Fo"Debug\byteasm.obj" /D"_DEBUG" /Fl"Debug\byteasm.lst" /W3 /errorReport:prompt /TaC:\Users\James\Documents\Dolphin\Core\DolphinVM\VMLib..\byteasm.asm
Assembling: C:\Users\James\Documents\Dolphin\Core\DolphinVM\VMLib..\byteasm.asm
Since I can execute the same thing (?) from the command line I don't understand why VisualStudio is reporting an error. Any advice? Once I've done the assembly manually, can I tell VisualStudio to skip it?
The suggestion from #njuffa to increase the verbosity of the build was helpful and showed the error that it could not find ml.exe. I believe this is a bug in Version 17.3.0 Preview 6.0 since it is able to find the C++ compiler for x86. My workaround was to add the x86 tools directory to the path (which would break attempts to build for any other environment). Thanks to all for the helpful responses and advice!

msbuild with vcpkg uses different triplet from Visual Studio for x86, but works for x64

I have a library project for both x64 and x86. Within Visual Studio I can build both x64 and x86. When I use msbuild, the x64 builds with the correct triplet but the Win32 builds with x86-windows not the expected x86-windows-static. The vcproj file has the right triplets, as you can see from the snippet.
<VcpkgTriplet Condition="'$(Platform)'=='x64'">x64-windows-static</VcpkgTriplet>
<VcpkgTriplet Condition="'$(Platform)'=='Win32'">x86-windows-static</VcpkgTriplet>
Here is the example for the successful x64
VERBOSE: msbuild.exe C:\code\proj53\proj53.vcxproj /nologo /p:Configuration=Release
/t:Clean,Rebuild /p:DebugSymbols=false /p:platform=x64
VcpkgTripletSelection:
Using triplet "x64-windows-static" from "C:\code\vcpkg\installed\x64-windows-static\"
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\CL.exe
/c /Iinclude /I"C:\code\vcpkg\installed\x64-windows-static\include" /Zi /nologo ...
And here is the example for the failing x86. I don't understand why it is selecting x86-windows and not the x86-windows-static as given in the vxcproj.
VERBOSE: msbuild.exe C:\code\proj53\proj53.vcxproj /nologo /p:Configuration=Release
/t:Clean,Rebuild /p:DebugSymbols=false /p:platform=x86
VcpkgTripletSelection:
Using triplet "x86-windows" from "C:\code\vcpkg\installed\x86-windows\"
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\CL.exe
/c /Iinclude /I"C:\code\vcpkg\installed\x86-windows\include" /Zi /nologo ...
fatal error C1083: Cannot open include file: 'curl/curl.h'
fatal error C1083: Cannot open include file: 'tinyxml2.h'
Can anyone point me in the right direction?

Assembly Programs Not Compiling in x86 Build Visual Studio

so I'm trying to learn MASM, and I've looked online but I can't get it to compile in an x86 Build. I have a simple .asm file that just has
end
then a c file with main.
When I set VS with a x64 Build it compiles successfully with ml64; however, when I use x86 I get:
1>C:\Program Files (x86)\Microsoft Visual
Studio\2017\Community\Common7\IDE\VC\VCTargets\BuildCustomizations\masm.targets(50,5):
error MSB3721: The command "ml.exe /c /nologo /Zi /Fo"Debug\test.obj"
/W3 /errorReport:prompt /Tatest.asm" exited with code 1.

How to build SLN file from the command line using MSVC build tools

I am trying to build the Hunspell project on GitHub with MSVC 2017 build tools:
https://github.com/hunspell/hunspell
The project have a msvc folder containing a Hunspell.sln and libhunspell.vcxproj files (I am interested in the library)
My setup:
Windows 10
MSVC2017 build tools (15.9.3)
Windows 10 Kit: 10.0.17763.0
If I open the "x86 Native Tools Command Prompt for VS 2017" and try to build the solution I get the following error:
>msbuild libhunspell.vcxproj
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 2018/12/01 6:01:18 PM.
Project "c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\Win32\PlatformToolsets\v140_xp\Toolset.targets(36,5): warning MSB8003: Could not find WindowsSdkDir_71A variable from the registry. TargetFrameworkVersion or PlatformToolset may be set to an invalid version number. [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry. TargetFrameworkVersion or PlatformToolset may be set to an invalid version number. [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]
InitializeBuildStatus:
Touching "Debug\libhunspell\libhunspell.tlog\unsuccessfulbuild".
PreBuildEvent:
echo N | copy /-Y ..\src\hunspell\hunvisapi.h.in ..\src\hunspell\hunvisapi.h
:VCEnd
Overwrite ..\src\hunspell\hunvisapi.h? (Yes/No/All): N
0 file(s) copied.
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe /c /I..\src\hunspell /I. /ZI /nologo /W4 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _WINDOWS /D _USRDLL /D HUNSPELL_STATIC /D _CRT_SECURE_NO_WARNINGS /D _USING_V110_SDK71_ /D_MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\libhunspell\\" /Fd"Debug\libhunspell\libhunspell.pdb" /Gd /TP /wd4706 /wd4251 /wd4267 /analyze- /errorReport:queue ..\src\hunspell\csutil.cxx
csutil.cxx
c:\development\hunspell\hunspell-1.7.0\src\hunspell\csutil.cxx(84): fatal error C1083: Cannot open include file: 'windows.h': No such file or directory [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]
Done Building Project "c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj" (default targets) -- FAILED.
Build FAILED.
"c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj" (default target) (1) ->
(CheckWindowsSDK71A target) ->
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\Win32\PlatformToolsets\v140_xp\Toolset.targets(36,5): warning MSB8003: Could not find WindowsSdkDir_71A variable from the registry. TargetFrameworkVersion or PlatformTool set may be set to an invalid version number. [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]
"c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj" (default target) (1) ->
(PrepareForBuild target) ->
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry. TargetFrameworkVersion or PlatformToolset may be set to an invalid version number. [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]
"c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj" (default target) (1) ->
(ClCompile target) ->
c:\development\hunspell\hunspell-1.7.0\src\hunspell\csutil.cxx(84): fatal error C1083: Cannot open include file: 'windows.h': No such file or directory [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]
The important part in the above is the following: Cannot open include file: 'windows.h'
It seems like my console is set up correctly when looking at the INCLUDES variable:
echo %INCLUDE%
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt
I have tried many options like running as follow, with no luck:
> msbuild libhunspell.vcxproj /p:AdditionalIncludeDirectories="C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um"
I have also added the full path to the "um" and "shared" (for winapifamily.h) folders to the <AdditionalIncludeDirectories> property manually in the vcxproj file.
This works for the static libs, but I had to add the <AdditionalIncludeDirectories> to the <ResourceCompile> step.
For the dlls (Release_Dll, etc) linking did not work since I don't know how to fix this (yet).
The above feels wrong, I do not think that the solution can be to hack a project file for the compiler to know where its own files are.
Any help in this regard will be appreciated.
Note: I do not have Visual Studio IDE installed, most SO questions around this question involve steps to solve the issue by changing settings in Visual Studio. This does not apply to this question.
PS: I have no experience with msbuild or the build tools. I normally use the Qt Creator IDE for building with MSVC compiler.
How to build SLN file from the command line using MSVC build tools
You should install the Individual components VC++ 2015.3 v14.00 (v140) toolset for desktop via build tools.
According to the error log:
TargetFrameworkVersion or PlatformToolset may be set to an invalid
version number
When we open the libhunspell.vcxproj with notepad, we could to know following properties:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_dll|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v140_xp</PlatformToolset>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
So, to resolve this issue, we need install the toolset v140_xp. To accomplish this, Open the build tool, switch to the Individual components tab and select VC++ 2015.3 v14.00 (v140) toolset for desktop:
After that, I can build the peoject successfully:
Hope this helps.

Set up x64 in Visual C++ 2010

I am trying to learn x64 assembly using Visual Studion 2010.
I was following this video tutorial : x64 Assembly and C++ Tutorial 1: Getting into x64 ASM from C++
As it says, I installed Visual Studio 2010, windows 7 SDK 3.5 (ISO install) and edited the configuration.
But when I compile the code, I get following error :
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\masm.targets(49,5): error MSB3721: The command "ml64.exe /c /nologo /Zi /Fo"x64\Debug\asm.obj" /W3 /errorReport:prompt /Taasm.asm" exited with code 1.
What is this problem, and how can I solve it?
Look at the assembler output above that line, or build the .asm file by itself.
You should see warnings generated by the assembler
eg. "somefile.asm(564): warning A6004: procedure argument or local not referenced :"
Deal with those warnings. The "exited with code 1" is not very explanatory.

Resources