How can I see the explanation of an MSVC /analyze warning from the command line? - visual-c++

I would like to see the analyzer trace of the MSVC /analyze option:
Consider the following bad code.
#include <stdio.h>
int main()
{
int i;
printf("Uninit: %d\n", i);
}
After running cl.exe with /analyze it shows:
>cl.exe /analyze file.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30139 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
file.c
C:\redacted\file.c(6) : warning C6001: Using uninitialized memory 'i'.: Lines: 5, 6
C:\redacted\file.c(6) : warning C4700: uninitialized local variable 'i' used
Microsoft (R) Incremental Linker Version 14.29.30139.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:file.exe
file.obj
So in the lines section it shows line 5 and line 6 only. Obviously it's easy to see the problem in a simple code. But in real code that "Lines" at the end of the warning may show a dozen of lines. Like this:
warning C6386: Buffer overrun while writing to 'news': the writable size is '((newslen+wcslen(lastslash)+((sizeof((L"\\?\"))/sizeof(WCHAR)-1))+1))*sizeof(WCHAR)' bytes, but '8' bytes might be written.: Lines: 139, 140, 141, 142, 143, 144, 146, 147, 149, 151, 157, 159, 164, 168, 169, 172, 174, 180, 181, 187, 190, 191, 193, 194, 202
When using the Visual Studio IDE, it can show detailed explanation for those lines which reveals the assumptions the analyzer had.
But we are not using the IDE because only the Build tools are installed and the compiler is invoked using a build system (Bazel).
Is there a way to show detailed trace of analyzer warnings in the command line?
EDIT: I'm thinking about the messages such as "entering this loop", "assuming x is 0", "taking the then branch", etc. I don't know how these are called, Google failed me.

You want to use the Visual C++ /diagnostic command-line switch added Visual Studio 2017. Visual Studio defaults to /diagnostic:column but you may want to use /diagnostic:caret.
See this Visual C++ Team Blog post and Microsoft Docs.

Related

Pyinstaller error: 'SystemError: codesign failure!' on macOS

I have made an application that I am now distributing on macos and windows (windows successfully compiled) but when I try to compile my app it keeps throwing the error SystemError: codesign failure! In pyinstaller I am using the --onefile flag, and I have tried it without the flag (python pyinstaller.py app.py, I could not use python pyinstaller app.py as I was thrown command not found). This is the full error message:
326 INFO: Building PKG (CArchive) PKG-00.pkg
4245 WARNING: codesign command (['codesign', '-s', '-', '--force', '--all-architectures', '--timestamp', '/Users/admin/Library/Application Support/pyinstaller/bincache00_py39_64bit/x86_64/adhoc/no-entitlements/lib-dynload/resource.cpython-39-darwin.so']) failed with error code 1!
stdout: ''
stderr: '/Users/admin/Library/Application Support/pyinstaller/bincache00_py39_64bit/x86_64/adhoc/no-entitlements/lib-dynload/resource.cpython-39-darwin.so: invalid or unsupported format for signature\n'
Traceback (most recent call last):
File "/Users/admin/Documents/Cloud/hero/pyinstaller.py", line 17, in <module>
run()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/__main__.py", line 126, in run
run_build(pyi_config, spec_file, **vars(args))
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/building/build_main.py", line 815, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/building/build_main.py", line 762, in build
exec(code, spec_namespace)
File "/Users/admin/Documents/Cloud/hero/app.spec", line 23, in <module>
exe = EXE(pyz,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/building/api.py", line 509, in __init__
self.pkg = PKG(self.toc, cdict=kwargs.get('cdict', None),
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/building/api.py", line 208, in __init__
self.__postinit__()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/building/datastruct.py", line 159, in __postinit__
self.assemble()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/building/api.py", line 274, in assemble
fnm = checkCache(fnm, strip=self.strip_binaries,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/building/utils.py", line 391, in checkCache
osxutils.sign_binary(cachedfile, codesign_identity, entitlements_file)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PyInstaller/utils/osx.py", line 383, in sign_binary
raise SystemError("codesign failure!")
SystemError: codesign failure!
Since I have never compiled an app for mac and this is my first time doing it, I have no idea what this really means. This is using python 3.9.
This seems to be an issue with the way pyinstaller performs ad-hoc signing since codesigning changed sometime after 4.3 (see https://github.com/pyinstaller/pyinstaller/issues/6167). Building on the latest Big Sur (MacOS 11.5.2) should work fine but I assume you're on Catalina or earlier.
You can either:
Downgrade to pyinstaller 4.3 with pip uninstall pyinstaller and pip install -Iv pyinstaller==4.3 and then rebuild as you were.
or
Provide a certificate to sign the app yourself.
If you want to sign the app yourself you can do so like so:
Open Keychain Access
Go to the menu at the top of the screen and select Keychain Access > Certificate Assistant > Create a Certificate
In the window that appears change Certificate Type to Code Signing , select Create and note the name of the certificate
Build your pyinstaller source with the --codesign-identity <name> flag where <name> is the name of the certificate you created in step 3.

pyinstaller /waf failing even after installing c++

system: windows 10/64bit
Python: 3.6.7 /32-bit
pyinstaller - latest
I have set up a new system (the above) with python, eclipse IDE, and pyinstaller.
Initially I used pip install to install pyinstaller - but discovered I needed to download the source code. Ive downloaded the zip and extracted the source code.
I cd'd to the directory containing the script and attempted to compile a script using command
pyinstaller --onefile AXLSoapTest14.py
the script appeared to compile but the executable failed.
The execution of pyinstaller ran without warnings or errors however running the executable from an elevated command prompt gives these errors:
C:\Users\t01136\eclipse-workspace\AXLSoap4\dist>AXLSoapTest14.exe
Traceback (most recent call last):
File "AXLSoapTest14.py", line 49, in <module>
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module
File "test\test_tools\test_unparse.py", line 13, in <module>
File "test\test_tools\__init__.py", line 17, in skip_if_missing
unittest.case.SkipTest: scripts directory could not be found
[12848] Failed to execute script AXLSoapTest14
In speaking with Mr Google, I found I may need to build the build the bootloader (tho I would have thought the install would fail outright).
I attempted to follow the instructions I found and CD'd to the bootloader folder of the extracted source code and attempted to execute:
python ./waf distclean all
I got the following errors:
Pyinstaller\bootloader>python ./waf distclean all
'distclean' finished successfully (0.001s)
'all' finished successfully (0.001s)
'distclean' finished successfully (0.001s)
Setting top to : C:\AXLdev\Python\pyinstaller\pyinstaller-develop\pyinstaller-develop\bootloader
Setting out to : C:\AXLdev\Python\pyinstaller\pyinstaller-develop\pyinstaller-develop\bootloader\build
Python Version : 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 12:45:02) [MSC v.1900 32 bit (Intel)]
Checking for 'msvc' (C compiler) : not found
Checking for 'gcc' (C compiler) : not found
Checking for 'clang' (C compiler) : not found
could not configure a C compiler!
(complete log in ```C:\AXLdev\Python\pyinstaller\pyinstaller-develop\pyinstaller-develop\bootloader\build\config.log)
I installed visual C++, rebooted and retried, but am getting the same error.
So the questions are:
Is my problem with the exe failing because the environment isnt set up?
If not, do I have 2 problems - one relating to the python waf command and then a second causing the compiled exe issue?
finally, what can I do to fix either or both of these problems?
The file Im trying to compile is over 1000 lines long so I didnt want to post it.
thanks for any help you can give!
w

ValueError: Protocol message SsdFeatureExtractor has no field replace_preprocessor_with_placeholder

I'm using an object-detection API to train my own model, but while running the training using this command:
python train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/ssd_mobilenet_v1_coco.config
I get this error:
WARNING:tensorflow:From C:\Users\MHD\Anaconda3\envs\tf15\lib\site-packages\tensorflow\python\platform\app.py:124: main (from __main__) is deprecated and will be removed in a future version.
Instructions for updating:
Use object_detection/model_main.py.
Traceback (most recent call last):
File "train.py", line 179, in <module>
tf.app.run()
File "C:\Users\MHD\Anaconda3\envs\tf15\lib\site-packages\tensorflow\python\platform\app.py", line 124, in run
_sys.exit(main(argv))
File "C:\Users\MHD\Anaconda3\envs\tf15\lib\site-packages\tensorflow\python\util\deprecation.py", line 136, in new_func
return func(*args, **kwargs)
File "train.py", line 175, in main
graph_hook_fn=graph_rewriter_fn)
File "C:\tensorflow1\models\research\object_detection\legacy\trainer.py", line 249, in train
detection_model = create_model_fn()
File "C:\tensorflow1\models\research\object_detection\builders\model_builder.py", line 119, in build
return _build_ssd_model(model_config.ssd, is_training, add_summaries)
File "C:\tensorflow1\models\research\object_detection\builders\model_builder.py", line 237, in _build_ssd_model
is_training=is_training)
File "C:\tensorflow1\models\research\object_detection\builders\model_builder.py", line 187, in _build_ssd_feature_extractor
if feature_extractor_config.HasField('replace_preprocessor_with_placeholder'):
ValueError: Protocol message SsdFeatureExtractor has no field replace_preprocessor_with_placeholder
please help me guys
Tracing down the cause of this error, I found the option replace_preprocessor_with_placeholder was recently added. Here is the commit record. (On that page if you search for replace_preprocessor_with_placeholder you will find that it was added recently on March 7th, 2019).
So the cause of the error is obviously your proto files version is not consistent with the code version. If you compare object_detection/protos/ssd.proto on your local machine and on the github repo, you will probably find this line does not exist on your local machine's file (because this filed was also added recently!).
The easiest way to fix this error is to reinstall the object detection api following this guide.
Since you already have all packages installed, essentially there are two steps you need to do, install the coco api and compile the protobuff. A new protobuff compilation will fix your error.
Also I recommend you follow the latest api tutorial, I see in your call you are using train.py, this file has now been put in the legacy folder and is not recommended to run since they may not be up-to-date.

Compiling Python Package on Windows

My apology if this may not be the right place to post my question. I recently had to update Windows 10 system on a Lenovo Yoga 910 laptop. Following the system update, I successfully installed Python 3.7.2, which I primarily use with Abjad, a music composition package.
The installation of the Abjad package was successful and all required components for the package appear to be successfully installed and callable from the terminal. However, when I compile it I get this error message:
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import abjad
>>> note = abjad.Note()
>>> abjad.show(note)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\nagym\AppData\Local\Programs\Python\Python37\lib\site-packages\abjad\top\show.py", line 51, in show
result = abjad.persist(argument).as_pdf(**keywords)
File "C:\Users\nagym\AppData\Local\Programs\Python\Python37\lib\site-packages\abjad\system\PersistenceManager.py", line 234, in as_pdf
**keywords
File "C:\Users\nagym\AppData\Local\Programs\Python\Python37\lib\site-packages\abjad\system\PersistenceManager.py", line 67, in as_ly
lilypond_file = illustrate_function(**keywords)
File "C:\Users\nagym\AppData\Local\Programs\Python\Python37\lib\site-packages\abjad\core\Component.py", line 118, in __illustrate__
lilypond_file = abjad.LilyPondFile.new(self)
File "C:\Users\nagym\AppData\Local\Programs\Python\Python37\lib\site-packages\abjad\lilypondfile\LilyPondFile.py", line 990, in new
use_relative_includes=use_relative_includes,
File "C:\Users\nagym\AppData\Local\Programs\Python\Python37\lib\site-packages\abjad\lilypondfile\LilyPondFile.py", line 147, in __init__
token = LilyPondVersionToken()
File "C:\Users\nagym\AppData\Local\Programs\Python\Python37\lib\site-packages\abjad\lilypondfile\LilyPondVersionToken.py", line 27, in __init__
version_string = abjad_configuration.get_lilypond_version_string()
File "C:\Users\nagym\AppData\Local\Programs\Python\Python37\lib\site-packages\abjad\system\AbjadConfiguration.py", line 412, in get_lilypond_version_string
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
File "C:\Users\nagym\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:\Users\nagym\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1178, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
>>>
I don't think that the problem I have may necessarily be related to the above Python package installation, given that the same package compiles just fine on Linux and Mac systems. In fact, the package worked perfectly on Windows before the update.
While I have already inquired about this on relevant Abjad forum sites, I wonder if perhaps some folks on this list with more extensive Windows-Python background may be able to read the above error message and point me in the right direction? Could it be that what I'm experiencing may be more like an IT issue, or perhaps a lack of proper Windows setup?
Thank you!
Resetting the PC solved the problem. I'm still not sure what was the cause of the problem and why Python didn't want to compile the package earlier.
I appreciate the opportunity to ask the question.

CompileError : command 'C:\\MinGW\\bin\\gcc.exe' failed with exit status 1 while installing pystan

i'm trying to get pystan to work on Windows 10 in order to use the fbprophet package for time series. I have already installed MinGW, added its directories to my PATH environment variable and tried this piece of code to verify everything is working fine:
gcc -dumpversion
ld -v
dllwrap -version
which yields these results:
C:\WINDOWS\system32>gcc -dumpversion
6.3.0
C:\WINDOWS\system32>ld -v
GNU ld (GNU Binutils) 2.28
C:\WINDOWS\system32>dllwrap -version
GNU dllwrap (GNU Binutils) 2.28
Copyright (C) 2017 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.
everything iw working fine to this point.
The problems comes when once in python, i try to execute the following code:
import pystan
model_code = 'parameters {real y;} model {y ~ normal(0,1);}'
model = pystan.StanModel(model_code=model_code)
y = model.sampling(n_jobs > 1).extract()['y']
y.mean() # with luck the result will be near 0
for which i'm getting this output:
import pystan
model_code = 'parameters {real y;} model {y ~ normal(0,1);}'
model = pystan.StanModel(model_code=model_code)
y = model.sampling(n_jobs > 1).extract()['y']
y.mean() # with luck the result will be near 0
INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_5944b02c79788fa0db5b3a93728ca2bf NOW.
Traceback (most recent call last):
File "<ipython-input-3-941feb69c4c4>", line 3, in <module>
model = pystan.StanModel(model_code=model_code)
File "Z:\Anaconda3\lib\site-packages\pystan\model.py", line 313, in __init__
build_extension.run()
File "Z:\Anaconda3\lib\distutils\command\build_ext.py", line 339, in run
self.build_extensions()
File "Z:\Anaconda3\lib\distutils\command\build_ext.py", line 448, in build_extensions
self._build_extensions_serial()
File "Z:\Anaconda3\lib\distutils\command\build_ext.py", line 473, in _build_extensions_serial
self.build_extension(ext)
File "Z:\Anaconda3\lib\distutils\command\build_ext.py", line 533, in build_extension
depends=ext.depends)
File "Z:\Anaconda3\lib\distutils\ccompiler.py", line 574, in compile
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
File "Z:\Anaconda3\lib\distutils\cygwinccompiler.py", line 175, in _compile
raise CompileError(msg)
CompileError: command 'C:\\MinGW\\bin\\gcc.exe' failed with exit status 1
I have searched on the website prior to posting this question, as well as in other websites, but nothing seems to work for me. I'd appreciate any help.
Thanks in advance

Resources