0

我刚刚在带有 SP3 的 Windows XP Professional 上安装了 Windows SDK 7.1。现在我正在检查安装是否正常,并且我已经遇到了问题。我仍然无法让 cl.exe 从 Windows SDK 7.1 命令提示符编译一个简单的 hello world C++ 代码。这是命令提示符输出的快照:

Setting SDK environment relative to C:\Program Files\Microsoft SDKs\Windows\v7.1\.
Targeting Windows XP x86 Debug


C:\Program Files\Microsoft SDKs\Windows\v7.1>cd /d "D:\My Documents\Sources"

D:\My Documents\Sources>cl /EHsc /FeD:\Target\hello hello.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

hello.cpp
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

LINK : fatal error LNK1104: cannot open file 'C:\Documents'

我尝试移至hello.cppD:\ 并得到相同的结果。另一方面,CSC.exe 在同一命令提示符下顺利编译了 hello world C# 代码。我现在该怎么办?

请注意,我没有安装任何版本的 Visual Studio。我安装了 Windows SDK,以便可以在 Qt Creator 中使用用于 VS2010 的 Qt Framework 4.8.0,并在 SharpDevelop 中学习一点 C#。

4

1 回答 1

0

Some people adviced me to wrap all environment variable values containing C:\Documents and Settings\ in double quotes, e.g.: Set ALLUSERSPROFILE="C:\Documents and Settings\All Users", Set USERPROFILE="C:\Documents and Settings\Ant Luc", and so forth. There was no sane way to perform the modification, except for %TEMP% and %TMP%, since they were not available for editing through System Properties > Advanced > Environment Variables. So I edited C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd and added the following lines right below @ECHO OFF:

SET ALLUSERSPROFILE="C:\Documents and Settings\All Users"
SET USERPROFILE="C:\Documents and Settings\Ant Luc"
SET HOMEPATH="C:\Documents and Settings\Ant Luc"
SET APPDATA="%USERPROFILE%\Application Data"
SET TEMP="%USERPROFILE%\Local Settings\Temp"
SET TMP="%USERPROFILE%\Local Settings\Temp"

But I then got Error C1083 when compiling the hello world code with cl.exe. In desperation, I edited C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd again, and changed the value for %TMP% to D:\VSTEMP, created a directory called VSTEMP in D:\, tried to compile the source code again, and sighed in relief because it finally compiled successfully.

I decided to grab and install Visual Studio 2010 Express out of curiosity, opened Visual Studio Command Prompt, tried to compile the same hello world code, and was faced with the same set of problems which I fixed with the same workaround. Conclusion: the compiler (or linker) cannot properly handle whitespace in %TMP% -- assign a directory without a single whitespace to it.

I still do not know what is wrong with my setup, but all this hassle seems stupid anyway. FWIW, this is the first toolchain that made me jump through hoops just to get a hello world code compile successfully.

于 2011-12-22T05:24:04.630 回答