简体   繁体   English

为什么我的C代码没有编译为EXE

[英]Why Isn't My C Code Being Compiled To An EXE

I'm just starting out writing trying to write a simple program in C and I am using Visual Studios to do so. 我刚开始尝试使用C语言编写一个简单程序,而我正在使用Visual Studios来编写。 I heard that it does compile C as well as C++. 我听说它可以编译C和C ++。 And I know that it does because it says it compiles. 我知道这样做是因为它说它可以编译。 The only problem is that when I go to the output directory, there isn't a .exe file in the directory! 唯一的问题是,当我转到输出目录时,该目录中没有.exe文件! It has the following: 它具有以下内容:

  • BuildLog.html BuildLog.html
  • mt.dep 深山
  • test1.obj test1.obj
  • vc90.idb vc90.idb
  • vc90.pdb vc90.pdb

But that is all! 但这就是全部! No EXE. 没有EXE。 I've looked through all the options and made sure that it is set to compile to an exe and i checked the output file. 我浏览了所有选项,并确保将其设置为编译为exe,然后检查了输出文件。 That is $(OutDir)\\$(ProjectName).exe. 那是$(OutDir)\\ $(ProjectName).exe。 But alas, no exe appears. 但可惜,没有exe出现。 Any ideas? 有任何想法吗?

Also when i try to hit f5 and run with debut i get an error that says 另外,当我尝试打F5并首次亮相时,我得到一个错误,提示

This application has failed to start because MSVCR90.DLL was not found. 此应用程序无法启动,因为找不到MSVCR90.DLL。 Re-installing the application may fix this problem 重新安装该应用程序可能会解决此问题

By default when you're creating a new C++ project within a new solution, you're getting folder structure like this: 默认情况下,当您在新解决方案中创建新的C ++项目时,将得到如下所示的文件夹结构:

C:\\Projects\\YourSolution C:\\Projects\\YourSolution\\YourCppProject C:\\ Projects \\ YourSolution C:\\ Projects \\ YourSolution \\ YourCppProject

YourSolution contains YourSolution.sln and YourCppProject contains YourCppProject.vcproj. YourSolution包含YourSolution.sln,而YourCppProject包含YourCppProject.vcproj。

When you build the solution, all intermediate files from YourCppProject are getting stored under YourCppProject\\Debug or YourCppProject\\Release, but resulting YourCppProject.exe goes under YourSolution\\Debug or YourSolution\\Release. 生成解决方案时,来自YourCppProject的所有中间文件都存储在YourCppProject \\ Debug或YourCppProject \\ Release下,但结果YourCppProject.exe放在YourSolution \\ Debug或YourSolution \\ Release下。

Your $(OutDir) is configured by General -> Output Directory. $(OutDir)由General-> Output Directory配置。 Check project configuration for YourCppProject and see that it uses $(SolutionDir) for the output. 检查YourCppProject的项目配置,看看它使用$(SolutionDir)作为输出。

is it a C/C++ console application? 它是C / C ++控制台应用程序吗? did you use the project wizard to create it? 您是否使用项目向导创建了它?

do you have a function like 你有类似的功能吗

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
    printf("Hello, world!\n");
    return 0;
}

in a .c module, typically main.c? 在.c模块中,通常是main.c?

what happens when you hit F5 to run-with-debug? 当您按F5键进行调试时会发生什么? what does your build log look like? 您的构建日志是什么样的?

The simplest thing to do is just start over, making sure you choose the right kind of project. 最简单的操作就是重新开始,确保选择正确的项目。

To compile plain old C code with Visual Studio, choose Visual C++ > General > Empty Project from the New Project menu. 要使用Visual Studio编译普通的旧C代码,请从“新建项目”菜单中选择“ Visual C++ > General > Empty Project ”。 This creates 3 empty folders: Header Files, Resource Files, and Source Files. 这将创建3个空文件夹:头文件,资源文件和源文件。 Right click on Source Files, choose Add > New Item . 右键单击源文件,选择Add > New Item Then add a main.cpp , rename it to main.c , and start coding. 然后添加一个main.cpp ,将其重命名为main.c ,然后开始编码。

http://msdn.microsoft.com/en-us/library/ms235299.aspx http://msdn.microsoft.com/en-us/library/ms235299.aspx

Note: 注意:

It is not supported to redistribute C/C++ applications that are built without a manifest. 不支持重新分发没有清单构建的C / C ++应用程序。 Visual C++ libraries cannot be used by C/C++ applications without a manifest binding the application to these libraries. 没有将应用程序绑定到这些库的清单,C / C ++应用程序不能使用Visual C ++库。 For more information, see Choosing a Deployment Method. 有关更多信息,请参见选择部署方法。

If the DLL is not reachable and Windows cannot load this DLL for your application, you may get the following error message: 如果无法访问该DLL,并且Windows无法为您的应用程序加载此DLL,则您可能会收到以下错误消息:

This application has failed to start because MSVCR90.dll was not found. 此应用程序无法启动,因为未找到MSVCR90.dll。 Re-installing the application may fix this problem. 重新安装该应用程序可能会解决此问题。

To resolve these errors, you must make sure that your application is built correctly and Visual C++ libraries are correctly deployed on the target system. 要解决这些错误,必须确保正确构建了应用程序,并且在目标系统上正确部署了Visual C ++库。 To identify the root cause of these run-time errors, follow the steps outlined in Troubleshooting C/C++ Isolated Applications and Side-by-side Assemblies. 要确定这些运行时错误的根本原因,请按照C / C ++隔离应用程序和并行程序疑难解答中概述的步骤进行操作。

HTH 高温超导

听起来您只点击了compile,就会得到.obj文件,但仍然需要单击build。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM