Visual Studios 在没有 main() 的情况下构建和调试.cpp文件
Visual Studios building and debugging .cpp file without main()
教授刚刚给了我们一个C ++代码块,以便了解Visual Studio中的调试窗口,但是在创建一个空白的win32控制台项目然后拖入.cpp文件后,我在尝试调试时收到丢失.exe错误消息。我到处找过,没有一个机构完全回答这个问题,我认为在这一点上,一定是代码有问题。
// Test1.cpp : main project file.
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace System;
int accum = 0;
int sum (int x, int y)
{
int t = x + y;
accum += t;
return t;
}
int calc (int op1, int op2, int opcode)
{
__asm
{
mov ebx, opcode;
test ebx, 0x01;
jz sub_2;
mov eax, op1;
add eax, op2;
jmp done;
sub_2:
test ebx, 0x02;
jz mul_3;
mov eax, op1;
sub eax, op2;
jmp done;
mul_3:
done:
}
}
int main()
{
int j = -2;
int i = 0;
int k = 0;
float f = 0.0;
char ch;
int int_array[5];
struct customer
{
char name[20];
short age;
int flag;
};
struct customer c[10];
ch = 'A';
ch |= 0x20;
i = j * 10 / 5;
if (i != 0)
goto cont;
j = i / 0;
cont:
i = sum ( j, -123 );
printf("decimal = %d, hex = 0x%4xn", i, i);
for (i = 0; i < 5; i++)
int_array[i] = i + 100;
switch (i) {
case 100:
k = k / i;
break;
case 200:
k = k % i;
break;
case 300:
case 400:
k += 256;
break;
default:
f = 1.0;
}
printf("f = %fn", f);
strcpy(c[3].name,"Larry King");
c[3].age = 65;
c[3].flag = 10;
c[3].flag = c[3].flag << 5;
strcpy(c[3].name,"Larry King ");
k = calc(i, j, 1);
k = calc(i, j, 2);
return 0;
}
您的代码确实有一个 main 函数,这是它工作所必需的。
正如您所说,调试器返回了"缺少可执行文件"错误,我假设您没有编译代码,或者如果是这样,则有一些错误,可以在输出和错误窗口中找到。
如果您正在处理具有单个源文件的空白项目,我会说没有必要使用预编译的标头(它可能丢失,因此会导致错误)。
我建议您重新生成代码并重试。如果错误仍然存在,请告诉我们"输出"窗口的内容。
控制台程序必须具有 main。
相关文章:
- 可以在没有构建代码的情况下转到定义吗?
- 如何在没有任何依赖库的情况下在Visual Studio中构建dll?
- 在没有root权限的情况下安装NTL,并在生成文件中修改其构建路径
- 通过CMake在没有Qt Creator的情况下构建Qt5 Quick项目
- 如何使用OpenCV从已知的3D点云(在没有I的情况下构建)估计新图像I的相机姿态矩阵
- 如何在不使用tensorflow的情况下构建tfsensor并将其提供给我的docker服务器
- 我如何在不启用例外的情况下构建Boost 1.70.0
- VS Code - 如何在不再次构建的情况下运行未更改的 c++ 文件
- 有没有一种方法可以在不使用std ::移动的情况下初始化类构建类的类
- 无法在不使用RTTI构建LLVM的情况下链接LLVM编译器教程程序
- 在不复制的情况下构建范围内的向量
- 如何在断言同时打开和关闭的情况下构建库
- 如何在没有调试符号和优化的情况下创建 cmake 构建配置
- 大多数为 Qt 5.3.2 编译的二进制文件都是在没有调试信息的情况下构建的
- 在启用 SSL 的情况下构建 libircclient 时对 'DLopen' 的未定义引用
- 需要在没有预定义缓冲区大小的情况下C++构建字符串
- clang与gcc运行时的区别:用clang构建的c++类模板在没有复制构造函数的情况下崩溃,用复制构造函数构建的gcc
- 开源库的代码是如何构建的,如何在不安装的情况下使用库?
- 在不知道大小的情况下在Borland c++构建器中定义AnsiString矩阵
- 默认情况下使用g++而不是arm编译器进行构建