How to suppress warnings in external headers in Visual C++

Use this method around (a) header(s) that you cannot or don’t want to change, but which you need to include. You can selectively, and temporarily disable all warnings like this: #pragma warning(push, 0) // Some include(s) with unfixable warnings #pragma warning(pop) Instead of 0 you can optionally pass in the warning number to disable, so … Read more

fopen deprecated warning

It looks like Microsoft has deprecated lots of calls which use buffers to improve code security. However, the solutions they’re providing aren’t portable. Anyway, if you aren’t interested in using the secure version of their calls (like fopen_s), you need to place a definition of _CRT_SECURE_NO_DEPRECATE before your included header files. For example: #define _CRT_SECURE_NO_DEPRECATE … Read more

How to install Visual C++ Build tools?

I just stumbled onto this issue accessing some Python libraries: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools”. The latest link to that is actually here: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019 When you begin the installer, it will have several “options” enabled which will balloon the install size to 5gb. If you have … Read more

Why does fatal error “LNK1104: cannot open file ‘C:\Program.obj'” occur when I compile a C++ project in Visual Studio?

This particular issue is caused by specifying a dependency to a lib file that had spaces in its path. The path needs to be surrounded by quotes for the project to compile correctly. On the Configuration Properties -> Linker -> Input tab of the project’s properties, there is an Additional Dependencies property. This issue was … Read more

Automatically add all files in a folder to a target using CMake?

As of CMake 3.1+ the developers strongly discourage users from using file(GLOB or file(GLOB_RECURSE to collect lists of source files. Note: We do not recommend using GLOB to collect a list of source files from your source tree. If no CMakeLists.txt file changes when a source is added or removed then the generated build system … Read more