使用 cl.exe 进行命令行编译?

发布于 2024-12-11 13:41:36 字数 463 浏览 0 评论 0原文

我尝试使用 Visual Studio Express 2010 C++ 编译器而不使用 IDE。我在 C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin 中找到了 cl.exe。然而我有一些困难。首先,当我输入 cl 时,它会弹出一个警告,提示“程序无法启动,因为您的计算机中缺少 mspdb100.dll”。

所以我将 C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE 添加到系统路径,然后重试,但这一次:

致命错误 C1510:无法加载语言资源 clui.dll。

知道如何解决这个问题以便我可以编译吗?另外,我将如何设置路径,以便我可以从不包含 cl.exe 的解决方案文件夹中键入“cl main.cpp”等。目前我必须位于 bin 文件夹内。谢谢。

Am trying to use the Visual Studio Express 2010 C++ compiler without using the IDE. I found cl.exe in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin. However am having a few difficulties. Firstly it gave me a warning pop up when i type cl saying 'Program cannot start because mspdb100.dll is missing from your computer.'

So i add C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE to the system path and then try again, but this time:

fatal error C1510: Cannot load language resource clui.dll.

Any idea how to solve this so i can compile? Also how would i set up the path so i can just type 'cl main.cpp' etc, from within a solution folder that does not contain cl.exe. At the moment i have to be inside bin folder. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

南薇 2024-12-18 13:41:36

尝试从以下位置启动 Visual Studio 命令提示符

Start->
    All Programs ->
        Microsoft Visual Studio 2010 ->
            Visual Studio Tools ->
                Visual Studio Command Prompt 2010

或者,您可以通过在命令提示符中运行此命令来设置环境:(

"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86

注意:这将在运行后保留您的环境设置。)

(注意 2:更改 x86根据需要,选项有 x86ia64amd64x86_amd64x86_ia64

从那里您可以运行cl.exe。如果您希望每次运行 cl 时自动完成和撤消此操作,请创建一个包含以下内容的批处理文件:(

@echo off
%comspec% /c ""c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 && cl.exe %*"

/c 告诉命令提示符在运行此命令,以便您的环境恢复正常。)

然后将其命名为 cl.bat。将其放在某个文件夹中,并将该文件夹的路径添加到您的 PATH 环境变量中,确保它位于 cl.exe 的路径之前。 code>,以便每当您键入 cl 而不是 cl.exe 时都会执行此 cl.bat

我建议您只输入 cl .bat 在您的 system32/ 文件夹中,它应该出现默认安装时 cl.exe 路径之前。

或者,您可以按任意顺序添加它并始终键入 cl.bat,或者将其命名为其他名称,这样就不会造成混淆。

Try starting the Visual Studio Command Prompt from

Start->
    All Programs ->
        Microsoft Visual Studio 2010 ->
            Visual Studio Tools ->
                Visual Studio Command Prompt 2010

Alternatively, you can set up the environment by running this in a command prompt:

"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86

(note: this will leave your environment set up after running.)

(note2: change x86 as desired. options are x86, ia64, amd64, x86_amd64, x86_ia64)

From there you can run cl.exe. If you want this to be automatically done and undone whenever you run cl, create a batch file with this content:

@echo off
%comspec% /c ""c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 && cl.exe %*"

(the /c tells the command prompt to end the session after running this command, so your environment returns to normal.)

From there, name it cl.bat. Put this in a folder somewhere, and add the path to that folder to your PATH environment variable, making sure it comes before the path to cl.exe, so that this cl.bat is executed whenever you type cl instead of cl.exe

I recommend you just put cl.bat in your system32/ folder, it should come before cl.exe's path on a default installation.

Alternatively, you can add it in any order and always type cl.bat, or name it something else so there's no confusion.

神魇的王 2024-12-18 13:41:36

只需按照 jsvk 建议使用 vcvarsall.bat 即可:

"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86

之后,如果您可以避免很多头痛,请使用 devenv.exe 来构建您的东西:

devenv solutionfile.sln /build [ solutionconfig ] [ /project projectnameorfile [ /projectconfig name ] ]

有您可以使用 devenv /? 来检查许多其他命令行开关。

Just use vcvarsall.bat as jsvk suggested:

"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86

After that, use devenv.exe to build your stuff if you keep yourself safe from a lot of head-aches:

devenv solutionfile.sln /build [ solutionconfig ] [ /project projectnameorfile [ /projectconfig name ] ]

There are a lot of other command line switches which you can check with devenv /?.

又怨 2024-12-18 13:41:36

这是一项非常简单且艰巨的任务。首先将编译器路径添加到系统路径:C:\Program Files\Microsoft Visual Studio 10.0\VC\bin;接下来,打开命令提示符并将目录更改为源文件夹;然后执行vcvars32.bat文件,设置在x86上使用vc++的环境;之后,您现在可以输入 cl 来编译您的程序

This is a quite simple and strait forward task. Firstly add the compiler path to system path.:C:\Program Files\Microsoft Visual Studio 10.0\VC\bin; Next, open command prompt and change directory to your source folder; Then execute the vcvars32.bat file to setup the environment for using vc++ on x86; After this, you can now type cl to compile your program

瑕疵 2024-12-18 13:41:36

我安装了多个版本的VS;我为每个版本创建一个小 .BAT 文件,放置在路径中的某个位置,调用相关的“vcvarsall.bat”。例如,“vc9.bat”对于 VS2008 调用 vcvarsall.bat,而“vc10.bat”对于 VS2010 调用 vcvarsall.bat。我可以像往常一样打开一个普通的命令窗口,输入“vc9”,然后,该命令窗口已准备好使用 VS2008 进行编译等。

I have multiple versions of VS installed; I create a little .BAT file for each version, placed somewhere in the path, that calls the relevant "vcvarsall.bat". e.g. "vc9.bat" calls vcvarsall.bat for VS2008, while "vc10.bat" calls vcvarsall.bat for VS2010. I can open a normal command window as usual, type "vc9", and presto, that command window is ready to compile etc using VS2008.

相守太难 2024-12-18 13:41:36

当链接器内存不足时会发生该错误。
您可以使用 x64 工具架构 Visual studio 工具。

msbuild 命令行:

msbuild myproject.vcxproj /p:PreferredToolArchitecture=x64

或者,更好的是,将其添加到 .vcxproj 中的项目设置中。
要指定编译器和工具的 64 位版本,请将以下属性组元素添加到 Myproject.vcxproj 项目文件中的 Microsoft.Cpp.default.props 元素之后:

<PropertyGroup>  
    <PreferredToolArchitecture>x64</PreferredToolArchitecture>  
</PropertyGroup> 

这些选项将使 Visual studio 使用 amd64 架构下的工具文件夹(根据目标架构):
VC\bin\amd64
VC\bin\amd64_x86
VC\bin\amd64_arm

https://msdn.microsoft.com/en-us /library/dd293607.aspx

That errors occurs when the linker runs out of memory.
You can use the x64 tool architecture Visual studio tools.

msbuild command line:

msbuild myproject.vcxproj /p:PreferredToolArchitecture=x64

Or, better yet, add it to the project's settings in the .vcxproj.
To specify the 64-bit version of the compiler and tools, add the following property group element to the Myproject.vcxproj project file after the Microsoft.Cpp.default.props element:

<PropertyGroup>  
    <PreferredToolArchitecture>x64</PreferredToolArchitecture>  
</PropertyGroup> 

These options will make Visual studio use the tools under the amd64 architecture folders (according to the target architecture):
VC\bin\amd64
VC\bin\amd64_x86
VC\bin\amd64_arm

https://msdn.microsoft.com/en-us/library/dd293607.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文