不能使用Windows驱动程序工具包构建环境来声明变量。

时间:2022-04-02 23:29:46

I have a trivial driver, like so:

我有一个微不足道的司机,像这样:

#include <ntddk.h>

NTSTATUS DriverEntry(__in DRIVER_OBJECT* a, __in UNICODE_STRING* b)
{
    UNREFERENCED_PARAMETER(a);
    UNREFERENCED_PARAMETER(b);

    int c; // this fails the build

    return 0;
}

A trivial makefile

一个微不足道的makefile

TARGETNAME=main
TARGETTYPE=DRIVER
MSC_WARNING_LEVEL=/W4 /WX
SOURCES=main.c

With a non trival build output

使用非trival构建输出。

C:\Test>pushd %cd%

C:\Test>C:\WinDDK\7600.16385.1\bin\setenv.bat C:\WinDDK\7600.16385.1 fre x64 wnet
WARNING: x64 Native compiling isn't supported. Using cross compilers.
Launching OACR monitor

C:\WinDDK\7600.16385.1>popd

C:\Test>build

BUILD: Compile and Link for AMD64
BUILD: Loading c:\winddk\7600.16385.1\build.dat...
BUILD: Computing Include file dependencies:
BUILD: Start time: Thu Jan 17 10:57:58 2013
BUILD: Examining c:\test directory for files to compile.
BUILD: Saving c:\winddk\7600.16385.1\build.dat...
BUILD: Compiling and Linking c:\test directory
Configuring OACR for 'root:amd64fre' - <OACR on>
_NT_TARGET_VERSION SET TO WS03
Compiling - main.c
1>errors in directory c:\test
1>c:\test\main.c(9) : error C2143: syntax error : missing ';' before 'type'
Linking Executable - objfre_wnet_amd64\amd64\main.sys
1>link : error LNK1181: cannot open input file 'c:\test\objfre_wnet_amd64\amd64\main.obj'
BUILD: Finish time: Thu Jan 17 10:57:58 2013
BUILD: Done

    3 files compiled - 1 Error
    1 executable built - 1 Error

How on Earth can this result in a error C2143: syntax error : missing ';' before 'type'?

这究竟是如何导致一个错误的C2143:语法错误:缺少';'在'类型'之前?

Not all declerations fail, I seem to be able to declare globals but not local variables.

并不是所有的解密都失败了,我似乎能够声明全局变量,而不是局部变量。

1 个解决方案

#1


5  

The problem is that Microsoft C compilers only support C89 standard, which does not permit the intermingling of declarations and code. Change to:

问题是微软C编译器只支持C89标准,它不允许声明和代码的混合。改变:

{
    int c;

    UNREFERENCED_PARAMETER(a);
    UNREFERENCED_PARAMETER(b);

#1


5  

The problem is that Microsoft C compilers only support C89 standard, which does not permit the intermingling of declarations and code. Change to:

问题是微软C编译器只支持C89标准,它不允许声明和代码的混合。改变:

{
    int c;

    UNREFERENCED_PARAMETER(a);
    UNREFERENCED_PARAMETER(b);