C program compilation error - c

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.

Related

Hello World driver won't compile correctly

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.

How to compile a self created Apache module under windows in repeatable batch mode?

How to compile a self created Apache module under windows in repeatable batch mode (without using a tool that I have to compile with a tool that I have to compile first)?
I have got:
win 10 / german
visual studio build tools 2017 (as I have read somewhere that apache win is compiled via visual studio's cl)
apache 2.24 - compiled for 64-Bit
a demo apache module code 'mod_example_1.c' from here: https://httpd.apache.org/docs/2.4/developer/modguide.html
here is what I did:
tried to recompile aspx -> got stuck in perl error message -> gave up on this as learning perl seems to me like a one way into nowhere
found out, that windows apache is compiled via visual studio
tried to run:
[mypath]\cl -nologo -MD -W3 -O2 -c -DWIN32 -D_WINDOWS -DNDEBUG
-I[includepath1] -I[includepath2] -I[includepath3] -I[includepath4] -I[includepath5] mod_example_1.c
from within the path where I put mod_example_1.c, according to post 2 under
https://www.apachelounge.com/viewtopic.php?t=5611
(of cause bracket-strings [ ] are placeholders for real pathes or pathes+files on my computer)
This returned me german error messages:
mod_example_1.c(13): error C2054: Nach "module" muss "(" folgen
mod_example_1.c(13): error C2085: "example_module": Nicht in der formalen Parameterliste enthalten
mod_example_1.c(13): error C2143: Syntaxfehler: Es fehlt ";" vor "="
mod_example_1.c(30): warning C4013: "ap_hook_handler" undefiniert; Annahme: extern mit Rückgabetyp int
meaning:
mod_example_1.c(13): error C2054: "module" requires to be succeeded by "("
mod_example_1.c(13): error C2085: "example_module": Not part of the formal list of parameters
mod_example_1.c(13): error C2143: Syntaxfehler: ";" is missing, before "="
mod_example_1.c(30): warning C4013: "ap_hook_handler" undefined; assumption: external with return type int
I would think, that a missing capability in cl to parse the term 'module' indicates that cl cannot be used to compile apache-webserver-modules. However why is that guy from the other forum writing, it works like this? What do I miss?
There is an oddball apxs-for-windows available with mod_perl:
http://www.apache.org/dist/perl/win32-bin/

Can't include iostream in C using MS Visual C++?

I've been trying to learn C, and I'm stuck on including libraries. I need to use strcpy(), but that method is included in the iostream library, but whenever I try to include the library, the program gives me errors. I've tried using "iostream", "iostream.h", , , but it either gives me a "can't find iostream.h" error, or the program exceeds 100 errors and just crashes. Even if my code is empty, I still get the same thing. Here's the code:
#include "iostream"
int main(void)
{
}
Yup, just that much makes it crash already. And here's a part of the errors I'm getting (could never paste them all here):
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(37): error C2061: syntax error : identifier 'abs'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(37): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(39): error C2061: syntax error : identifier 'acos'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(39): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(39): error C2061: syntax error : identifier 'asin'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(39): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2061: syntax error : identifier 'atan'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2061: syntax error : identifier 'atan2'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2061: syntax error : identifier 'ceil'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(41): error C2061: syntax error : identifier 'cos'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(41): fatal error C1003: error count exceeds 100; stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
So yeah it even exceeds the 100 errors and the program just stops counting. I don't understand why, I'm just including a regular library. Is there an equivalent of strcpy()? I mainly wanted to use it like this (for practice):
#include "stdafx.h"
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
#include "iostream"
int main(void)
{
struct person
{
int id;
char name[50];
int age;
};
struct person p1;
p1.id = 5595;
strcpy(p1.name, "Myname");
p1.age = 18;
printf("%d%s%d", p1.id, p1.name, p1.age);
}
<iostream> is a C++ header (it deals with input/ouput streams, as the name implies). If you want strcpy, you need <string.h>.
If your source file is ".c", all you have to do is to rename it ".cpp".
Then it'll compile as C++, you'll have the C++ headers, and you'll be able to use C++ streams.
I don't see any need for iostreams, however.
Strcpy and friends are in "<string.h>". Just include it, and "stdio.h" (like you're doing); delete the "iostreams" #include ... and life should be good.
iostreams are a C++-only feature. The iostreams header file is written in C++, not C. (Yes, they are different languages!) Presumably, you're invoking the compiler in C mode, so when the compiler looks at the header file it of course throws lots of errors since many of the constructs used in iostream makes sense only in C++ mode.
If you want to use iostreams, you have to compile in C++ mode (and code in proper, modern C++ accordingly), use a different library that's C-only or work around it by implementing your own code as necessary.
In this case, all you apparently want to do is to use strcpy(). That is declared in the string.h, not iostream. (string.h is a C header file.) Just #include <string.h> and it should compile.

structure repetition error compiling C WinSock code in visual studio 2010

I have been trying to compile C source code in visual studio 2010. While compiling i am getting some errors like:
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\winnt.h(4277): error C2040: 'CONTEXT' : '_CONTEXT' differs in levels of indirection from 'binding *'
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\winuser.h(5341): error C2365: 'INPUT' : redefinition; previous definition was 'enumerator'
1>c:\documents and settings\xyz\desktop\abc\clause.h(72) : see declaration of 'INPUT'
1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(16): error C2011: 'timeval' : 'struct' type redefinition
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\WinSock2.h(176) : see declaration of 'timeval'
I searched for those error and but some hints that it is due to the change in order of the header files. But could not get the exact answer. May I know , How can I overcome this problem?
Following is the order of header file inclusions.
#include <WinSock2.h>
#include <Windows.h>
#include <stdio.h>
Thanks in advance.
See here - if you include windows.h explicitly with winsock2.h you have to add a #define WIN32_LEAN_AND_MEAN to make this work.
For historical reasons, the Windows.h
header defaults to including the
Winsock.h header file for Windows
Sockets 1.1. The declarations in the
Winsock.h header file will conflict
with the declarations in the
Winsock2.h header file required by
Windows Sockets 2.0. The WIN32_LEAN_AND_MEAN macro prevents the Winsock.h from being included by the Windows.h header.

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