CMake + Visual Studio 2019: error invalid argument '/Wno-narrowing' - c++

I downloaded the source code for a library that resembles the processing library but for c++ called libxd. I used CMake to generate project files for Visual Studio 2019 which worked successfully. When trying to compile the solution for all of the provided build modes, I get the following errors:
The first error invlaid numeric argument '/Wno-narrowing' is what I'm concerned about for now. I'm trying to figure out why this argument is being provided to the compiler. When looking in the properties window for the xd project in the solution I can see the command line arguments that are supposed to be provided to the compiler in the C/C++ > Command Line tab. I verified that there is no /Wno-narrowing option provided. When looking at the build output it can be seen that the option -Wno-narrowing is being provided to the compiler. Can someone help me figure out why this argument is being passed? I looked throughout the compiler properties window to see if I could see anything that would be affecting it but I can't see anything that would affect this.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\CL.exe /c /IC:\dev\libxd\include /IC:\dev\libxd\lib\glad\include /IC:\dev\libxd\lib\glm /IC:\dev\libxd\lib\stb\include /IC:\dev\libxd\lib\glfw\include /Zi /nologo /W3 /WX- /diagnostics:column /Od /Ob0 /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"xd.dir\Debug\\" /Fd"xd.dir\Debug\xd.pdb" /Gd /TP /errorReport:prompt -Wno-narrowing C:\dev\libxd\src\opensans.cpp
Tracking command:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Tracker.exe /d "C:\Program Files (x86)\MSBuild\15.0\FileTracker\FileTracker32.dll" /i C:\dev\libxd\build\xd.dir\Debug\xd.tlog /r C:\DEV\LIBXD\SRC\OPENSANS.CPP /b MSBuildConsole_CancelEventfa83e1bb599743cfa0c02eb67d579e28 /c "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\CL.exe" /c /IC:\dev\Users\olive\Downloads\libxd\include /IC:\dev\libxd\lib\glad\include /IC:\dev\libxd\lib\glm /IC:\dev\libxd\lib\stb\include /IC:\dev\libxd\lib\glfw\include /Zi /nologo /W3 /WX- /diagnostics:column /Od /Ob0 /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"xd.dir\Debug\\" /Fd"xd.dir\Debug\xd.pdb" /Gd /TP /errorReport:prompt -Wno-narrowing C:\dev\libxd\src\opensans.cpp
cl : command line error D8021: invalid numeric argument '/Wno-narrowing'
The command exited with code 2.

The error is caused because that's not a valid MSVC flag. The flag is there because the CMakeLists.txt file demands it:
set_source_files_properties(src/opensans.cpp PROPERTIES COMPILE_FLAGS -Wno-narrowing)
That project specifies what it supports for building under Windows and it's not MSVC.
Windows Prerequisites: mingw-w64 version >= 4.8.1
So you either need to build it in the supported way, or modify the build scripts to allow for MSVC.
That would entail figuring out what the flag does in gcc (disables diagnostic messages about narrowing issues) and finding the equivalent in MSVC, probably a /disable:nnnn variant, once you figure out the nnnn. Figuring that out should be relatively painless since MSVC will tell you that when you compile it - lots of Cnnnn - something to do with narrowing warning messages.
Or you could just disable the line that adds the flag (for MSVC builds only) and see if it still builds. Of course, in the spirit of open source, you should then notify the author what it took to get it going, they may be happy to support MSVC if the effort is not too high.

Related

Compiler warning for statement on same line as #endif

Consider code:
#include <stdio.h>
int main() {
int a = 4;
#if 1
printf("Hello world\n");
#endif a++;
printf("a is %d\n", a);
}
Inadvertently, statement a++; is on the same line as a #endif and is not evaluated. As a result, the final output is:
Hello world
a is 4
On x86-64 clang 12, this is captured as a warning with using option -Wextra-tokens. See here.
I tried compiling this on Visual Studio 2019 MSVC, with command line options:
/JMC /permissive- /ifcOutput "Debug\" /GS /analyze- /W3 /Zc:wchar_t /I"../include/" /ZI /Gm- /Od /sdl /Fd"Debug\vc142.pdb" /Zc:inline /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /FC /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\windows.pch" /diagnostics:column
There is no warning of any sort on compilation. Is there a setting that can be passed to the compiler in MSVC that detects extra tokens?
Edited to add:
As answered by user Nathan Pierson, it was indeed option /Za that worked. It does not seem to be on by default. I was also unable to use the Visual Studio Project Properties dialog to find out the option to set. Yet, one can feed in extra options manually thus:
There's compiler warning C4067. It looks like you need to set the flag /Za for it to apply to #endif directives.
In the Visual Studio properties page, this flag is controlled by the setting "Disable Language Extensions" in the Language subsection of the C/C++ section.

C++ compiler flags for profiling in Visual Studio

To accurately profile an application, under linux, it is recommended to have optimizations on and debug symbols on via compile options -O2 -g for gcc or g++. This enables profiling to include the user's C++ code and not point to assembly code instead as possible hotspots, for instance. See for instance, here.
In Visual Studio IDE, for usage of profilers, what are the equivalent compile/linking options?
In Release mode of Visual Studio, under "Whole Program Optimization" property sheet that comes loaded by default, the Debug Information Format gets set to Program Database with command line option /Zi. See image:
Is this the Visual Studio/Windows/MSVC (Cl.exe, MSBuild.exe) equivalent of -O2 -g? Or are there any other equivalent settings?
ETA: Under the default Visual Studio 2019 release mode settings, the following flags are set:
/permissive- /ifcOutput "x64\Release\" /GS /GL /W3 /Gy /Zc:wchar_t /I"E:\local\boost_1_72_0" /Zi /Gm- /O2 /sdl /Fd"x64\Release\vc142.pdb" /Zc:inline /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /Gd /Oi /MD /FC /Fa"x64\Release\" /EHsc /nologo /Fo"x64\Release\" /FA /Fp"x64\Release\windows.pch" /diagnostics:column
Have a look at the project properties, under C++ optimization. The IDE tells you everything.

missing *.lib file after build

Hi i wanted to use external library in my project so i downloaded sourcode from https://code.google.com/p/inih/ and i compiled it using Microsoft walkthrough http://msdn.microsoft.com/en-us/library/ms235627.aspx
Build started 16/01/2015 10:30:39.1>Project "c:\...\Projects\inihlib\inihlib\inihlib.vcxproj" on node 2 (Build target(s)).
1>ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /Zi /nologo /W3 /WX- /sdl /O2 /Oi /Oy- /GL /D WIN32 /D NDEBUG /D _LIB /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Release\\" /Fd"Release\vc120.pdb" /Gd /TP /analyze- /errorReport:prompt ...\INIReader.cpp
INIReader.cpp
Lib: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\Lib.exe /OUT:"c:\...\Projects\inihlib\Release\inihlib.lib" /NOLOGO /LTCG Release\INIReader.obj
inihlib.vcxproj -> c:\...\Projects\inihlib\Release\inihlib.lib
1>Done Building Project "c:\...\Projects\inihlib\inihlib\inihlib.vcxproj" (Build target(s)).
Build succeeded.
Time Elapsed 00:00:00.46
It looks like inihlib.lib should be in release folder but instead ive got only inih.obj and log file. What im doing wrong any ideas?
Question was answered by Shane; issue was simply looking in the wrong folder.
You might be looking in the wrong folder, you could be looking in c:...\Projects\inihlib\inihlib\Release
instead of
c:...\Projects\inihlib\Release? – Shane Haw 1 hour ago
Just copy-pasting this for people who come looking for an accepted answer.

TeamCity building C++ with Visual Studio Solution

I have a small test project that I want to build with TeamCity. In TeamCity I have created a build step with runner type 'Visual Studio' solution. The problem is it is not building. The error I get is:
error C1069: cannot read compiler command line
Here a part of the build log:
[16:55:05]ClCompile
[16:55:05]CL
[16:55:05]C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D WIN32 /D _DEBUG /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc120.pdb" /Gd /TP /analyze- /errorReport:queue UnitTest.cpp
[16:55:05]UnitTest.cpp
[16:55:05]c:\data\teamcity buildagent\work\d8c46b39964cb4dc\testlibrary\unittest.cpp(27, 0): error C1069: cannot read compiler command line
Try removing the space in the TeamCity build agent path:
c:\data**teamcity buildagent**\work\d8c46b39964cb4dc\testlibrary\unittest.cpp
There is a bug with the VS2013 compiler as documented here:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/82304c15-37e2-4761-8928-0c67e074bf47/error-c1069-cannot-read-compiler-command-line-on-visual-studio-2013-rc?forum=vcgeneral
(Note, this is referring to the RC and could now be fixed)

VS2008 C++ Release mode slower than Debug mode

I am working with mixed Native and Managed Visual C++, using STL in the Native. I have a strange problem. It seems that when I compile my software in Release mode with all the optimizations set, my software consistently runs slower than in Debug mode. What could be wrong here?
These are my Debug command line options:
/Od /D "WIN32" /D "_DEBUG" /D "_UNICODE" /D "UNICODE" /FD /EHa /MDd /Fo"Debug\" /Fd"Debug\vc90.pdb" /W3 /nologo /c /Zi /clr /TP /errorReport:prompt /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll"
These are my Release command line options:
/Oi /Ot /Oy /GT /GL /D "WIN32" /D "_SECURE_SCL=0" /D "_HAS_ITERATOR_DEBUGGING=0" /D "VC_EXTRALEAN" /D "_UNICODE" /D "UNICODE" /FD /EHa /MD /Fo"Release\" /Fd"Release\vc90.pdb" /W3 /nologo /c /clr /TP /errorReport:prompt /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll"
That's utterly impossible to diagnose from the command line switches, you have to use a profiler.
One thing that's relevant however is you using the /clr option. Unless you explicitly use #pragma managed in your code, everything will be translated to IL, even the STL template code. Which means that your optimization settings have no effect whatsoever since they only apply to generated machine code. You are then subject to what the JIT compiler does for optimization. It will not optimize by default when you have a debugger attached for example.
Try profiling the release version to see if you notice any obviously incorrect slowness. If needed, compare it to a profile output from the debug version.
Alternately if the debug version is subjectively "fast enough", just release that (although there might be reverse-engineering implications).