开发者

Command-Line Compilation

I'm trying to make a program, which would run cl.exe (C/C++ compiler) and compile a C++ program. Here's my code:

Module Module1

    Sub Main()
        Shell("C:\Program Files\Microsoft Visual Studio 10.0\VC\ _ 
        bin\cl.exe /EHsc ""C:\myprogram.cpp"" ")

        Console.WriteLine("Compilation Succeded")
        Console.ReadLine()
    End Sub

End Module

This doesn't compile the .cpp file. Do you have any ideas how to make this work?

EDIT: I entered "C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\cl.exe" /EHsc "C:\myprogram.cpp" in CMD and it didn't compile, but instead it threw an error ( This application has failed to start because mspdb100.dll was not found. )

EDIT开发者_开发技巧: I executed my program trough 'VS Command Prompt' and it compiled my program (it showed that it compiled), but there's no compiled exe and obj files.


You can run Program Files\Microsoft Visual Studio 10.0\VC\bin\cl.exe.

This path will change depending on the installed version of Visual Studio, the bitness of the OS, and the system drive.
You can find the path in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\InstallDir.
On my machine, it's C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\.

CL.exe isn't compiling your program because you have an incorrect command-line.
In particular, you probably need to surround the source path in double-quotes, not single-quotes.
To use double-quotes inside a string literal, double them: ".../EHsc ""Path.cpp"" "


Never mind, instead of using cl.exe I'm now using MSBuild. Much better.


single ticks ' cannot be used on a command line for files containing spaces. Try using double quotes " instead:

Shell("cl /EHsc ""a .cpp file"" ")


You're probably running into issues with spaces in the path for cl.exe. Try:

Shell("""C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\cl.exe"" /EHsc ""myprogram.cpp"" ")

Also make sure that myprogram.cpp is in the current directory for the program's run (or specify the full path to it on the command line).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜