Hello World driver won't compile correctly - c

I started out driver development, however I followed some tutorials I met online here and I am trying to compile my driver into a simple .sys file.
The code looks like this:
#include <ntddk.h>
#include <wdf.h>
#define UNREFERENCED_PARAMETER(P) (P)
VOID DriverUnload(PDRIVER_OBJECT driver)
{
DbgPrint("first:HelloWorld End!");
}
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pUnicodeString)
{
DbgPrint("first:HelloWorld Begin!");
pDriverObject->DriverUnload = DriverUnload;
return STATUS_SUCCESS;
}
Rather than compile, I get this very funny error:
Error C2220 warning treated as error - no 'object' file generated MyHelloWorldDriver C:\Users\****\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c 7
I am lost as I dont know where else to seek answers from. I have checked and checked all and I get this funny error which happens to work fine on other versions of Visual studio. If I remove the warnings, I don't see it to have a worry, it compiles fine and does not send any errors to my screen, why is this so?
I am using Visual studio 2019, what could I apparently be missing ??
PS
The warnings I get look like this
Error (active) E1097 unknown attribute "no_init_all" MyHelloWorldDriver C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\km\ntddk.h 372
Error (active) E1097 unknown attribute "no_init_all" MyHelloWorldDriver C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\km\ntddk.h 1093
Warning MSB8038 Spectre mitigation is enabled but Spectre mitigated libraries are not found. Verify that the Visual Studio Workload includes the Spectre mitigated libraries. See https://aka.ms/Ofhn4c for more information. MyHelloWorldDriver C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets 422
Error C2220 warning treated as error - no 'object' file generated MyHelloWorldDriver C:\Users\***\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c 7
Warning C4566 character represented by universal-character-name '\uFF01' cannot be represented in the current code page (1252) MyHelloWorldDriver C:\Users\***\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c 7
Warning C4100 'driver': unreferenced formal parameter MyHelloWorldDriver C:\Users\***\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c 5
Warning C4566 character represented by universal-character-name '\uFF01' cannot be represented in the current code page (1252) MyHelloWorldDriver C:\Users\***\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c 12
Warning C4100 'pUnicodeString': unreferenced formal parameter MyHelloWorldDriver C:\Users\***\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c 10

Looks like an issue with Visual Studio:
https://developercommunity.visualstudio.com/content/problem/549389/intellisense-error-e1097-because-intellisense-does.html
Here is a copy from that link:
With Visual C++ 2017 version 15.8 (compiler version 19.15.26726.0) a new undocumented Compiler option /d1initall and
a new attribute __declspec(no_init_all) got added to the Compiler. Intellisense (VS17 and 19) does not recognize this attribute and says its unknown.
The Problem is Intellisense not knowing about the existence of the no_init_all attribute.
This attribute is used in the official Windows SDK and WDK 10.0.18362.0 header files,
that means Intellisense displays this error for all projects that include
Windows Kits\10\Include\10.0.18362.0\um\winnt.h (Line 588 & 1093) or
Windows Kits\10\Include\10.0.18362.0\km\ntddk.h (Line 7597).
You can also reproduce the Error by simply defining a struct with __declspec(no_init_all) Attribute,
__declspec(no_init_all) struct A {};
This Compiles fine without any warnings/errors but Intellisense says its wrong.
It has been fixed on 29th of April, 2019.

A possible fix is to add this code to one of the main header files:
#if (_MSC_VER >= 1915)
#define no_init_all deprecated
#endif

you can activate precompiled header in Tools/option/Text-Editor/C C++/Extension and set Disable Automatic Precompiled Header to false.

Related

unscoped enums in C code with VS2015

I'm trying to compile the psutil module for Python, using VS 2015 and the Windows 10 SDK. Compilation fails with the following error:
c:\users\builder\documents\code\psutil\psutil\arch\windows\ntextapi.h(212): error C2365: 'ProcessBreakOnTermination': redefinition; previous definition was 'enumerator'
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\um\winternl.h(308): note: see declaration of 'ProcessBreakOnTermination'
c:\users\builder\documents\code\psutil\psutil\arch\windows\ntextapi.h(212): error C2086: '_PROCESSINFOCLASS2 ProcessBreakOnTermination': redefinition
c:\users\builder\documents\code\psutil\psutil\arch\windows\ntextapi.h(212): note: see declaration of 'ProcessBreakOnTermination'
Further investigation shows ProcessBreakOnTermination is part of an enum (PROCESSINFOCLASS) in winternl.h.
I believe this has to do with C++11's enforcement of scoped enums: https://msdn.microsoft.com/en-us/library/vstudio/2dzy4k6e(v=vs.110).aspx
However, I am lost on how to address this issue. If I try to add the class or struct bits as detailed on that MS website, I get compiler errors, since this is being compiled as C code. Why should the C++11 rules apply to C code here?
The solution I came up with was to wrap the offending dual-defined symbols in a #if.
(start of enum)
(last good entry)
#if _MSC_VER < 1900
(offending enum entry)
#endif
(next entry) = (last_good_entry)+2
Any nicer solutions are welcome!

how to get rid of "LINK : warning LNK4049: locally defined symbol "_xmlFree" imported"?

I build one DLL on windows with microsoft-visual-c 6.0 including the source code from libxml2. Now I have used some xmlFree() calls in my code and I now get the linker warning LNK4049.
I have not the slightest idea, how to get rid of this warning. I googled, but all info I found was above my comprehension (I use normally gcc under solaris). Is there a simple receipt (add/remove compiler-flag or #define/#undef or similar)?
Thanks,
Peter
I was getting this warning when statically linking against libxml2_a.lib with MSVC 11. I haven't tried the DLL version so I'm not sure if it is affected in the same way.
The solution was to define these symbols in your project or makefile to tell the libxml2 header files to assume static linkage and avoid dll-importing and dll-exporting the xmlFree variable at the same time:
LIBXML_STATIC
The same applies to libxslt/libexslt too:
LIBXSLT_STATIC
LIBEXSLT_STATIC
Hope this helps.
I will add bit more context for others who face similar error like following.
We did libxml upgrade from 2.9.4 to 2.9.14 and we observed following errors which are similar to above .
warning LNK4217: locally defined symbol xmlStrcmp imported in function
"void __cdecl ::updateRunElement(struct _xmlNode *,class xml::XmlDoc &,struct _xmlNode *,struct const &)"
(?updateRunElement#YAXPEAU_xmlNode##AEAVXmlDoc#xml#2##2##Z)
LINK : error LNK1218: warning treated as error; no output file generated
warning LNK4217: locally defined symbol xmlFreeDoc imported in function "public: __cdecl xml::XmlDoc::~XmlDoc(void)" (??1XmlDoc#xml##QEAA#XZ)
LINK : error LNK1218: warning treated as error; no output file generated
All the other answers for this error points to set runtime library to /md (Multithreaded dll) or viceversa.
I also tried to suppress these warning by
#pragma warning( disable : 4217 1218) and also by project setting "Disable Specific Warnings" but both did not work as keep giving warnings/errors.
But as #vladimir. (Thanks for the answer) suggested defining LIBXML_STATIC as preprocessor in the project where you are using libxml library either as static or dynamically linked should fix all these warning errors.

warning LNK4017: DESCRIPTION statement not supported for the target platform; ignored

When I porting source code from VC++6 to VC++9 on visual studio 2008 I got this warning.
warning LNK4017: DESCRIPTION statement not supported for the target platform; ignored
I opened the *.def file that given me this warning but I still don't know how to fix this warning. This is the content:
; sctcomDLL.def : DLL 用のモジュール パラメータ宣言
LIBRARY "SCTCOMDLL"
DESCRIPTION 'SCTCOMDLL Windows Dynamic Link Library'
EXPORTS
; 明示的なエクスポートはここへ記述できます

C program compilation error

I am new to programming and picked up the C language as my first computer language. I was doing a sample conversion program and when i compiled the code, i get the following error.
What does it mean and how do i fix it?
Thanks!
1>------ Build started: Project: ConversionProgram, Configuration: Debug Win32 ------
1>Build started 24-07-2012 20:58:37.
1>InitializeBuildStatus:
1> Touching "Debug\ExcerciseProgram1.unsuccessfulbuild".
1>ClCompile:
1> conversion.cpp
1>c:\my documents\visual studio 2010\projects\excerciseprogram1\excerciseprogram1\question2.cpp(12): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf'
1>c:\my documents\visual studio 2010\projects\excerciseprogram1\excerciseprogram1\question2.cpp(18): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\my documents\visual studio 2010\projects\excerciseprogram1\excerciseprogram1\question2.cpp(32): error C2857: '#include' statement specified with the /YcStdAfx.h command-line option was not found in the source file
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.1
I am using VB 2010 as my IDE
The reason why you are experiencing a compile error is mentioned here:
error C2857: '#include' statement specified with the /YcStdAfx.h command-line option was not found in the source
This means that the compiler is making the inclusion of StdAfx.h compulsory. You can remedy this by adding #include <StdAfx.h> to your source code.
It seems that your source file is not including the precompiled header file. All source files must, as first non-comment, include "stdafx.h" if you are using precompiled headers.

Compilation error in visual C++

I am using Visual studio 2010 for building C project. My project contains a number of header files,source file and parsers. It uses lex and bason files. I am getting a single error during the compilation and íé the following
abc.y:error C2065: 'INPUT' : undeclared identifier
I tried the solutions I am getting like including
#define WIN32_WINNT >= 0x0501
in my main.c file before the inclusion of any of the header files.I am not able to get rid of this error. Could you please let me know what Can be the reasons for this error?
EDIT
The snippet of code that is showing error is:
list_Cons(0, list_List((POINTER)INPUT)
The surprising thing is that If i alter INPUT into INPUT1, I get the same error. It is stoic to change.
Presumably you read this and this.
#define WIN32_WINNT >= 0x0501 wont work. You should try using #define WIN32_WINNT 0x0501 instead.
Also, check that you are actually #including winuser.h
A C++ compiler cannot process a *.y file. For that you need a yacc / bison program, which does not come included with Visual Studio 2010.
For myself I use CMake which can generate MSVC projects along with other build types. You can tell it that a .y needs to be processed outwith the C/C++ files and it will instruct MSVC to invoke whatever external tools are necessary to preprocess the non-C/C++ parts.

Resources