秋天树下的太阳 2022-08-10 14:37 采纳率: 62.5%
浏览 66
已结题

编译器一直报[Error] ld returned 1 exit status,请各位解答一下

我在编程序的时候遇到了一个问题

#include <complex.h>
#include <fenv.h>
#include <inttypes.h>
#include <stdbool.h> 
#include <stdint.h>
#include <tgmath.h>
#include <bits/stdc++.h>
#include <chrono>
#include <stdio.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <wchar.h>
#include <wctype.h>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <bits/stdc++.h>
#include <windows.h>
#include <bits.h>
using namespace std;
int CaptureImage(HWND hwnd, const char *dirPath, const char *filename)
{
HANDLE hDIB;
HANDLE hFile;
DWORD dwBmpSize;
DWORD dwSizeofDIB;
DWORD dwBytesWritten;
CHAR FilePath[MAX_PATH];
HBITMAP hbmScreen = NULL;
BITMAP bmpScreen;
BITMAPFILEHEADER bmfHeader;
BITMAPINFOHEADER bi;
CHAR *lpbitmap;
INT width = GetSystemMetrics(SM_CXSCREEN); // 屏幕宽
INT height = GetSystemMetrics(SM_CYSCREEN); // 屏幕高
HDC hdcScreen = GetDC(NULL); // 全屏幕DC
HDC hdcMemDC = CreateCompatibleDC(hdcScreen); // 创建兼容内存DC

if (!hdcMemDC)
{
DeleteObject(hbmScreen);
DeleteObject(hdcMemDC);
ReleaseDC(NULL, hdcScreen);
return 0;
}

// 通过窗口DC 创建一个兼容位图
hbmScreen = CreateCompatibleBitmap(hdcScreen, width, height);
if (!hbmScreen)
{
DeleteObject(hbmScreen);
DeleteObject(hdcMemDC);
ReleaseDC(NULL, hdcScreen);
return 0;
}
// 将位图块传送到我们兼容的内存DC中
SelectObject(hdcMemDC, hbmScreen);
if (!BitBlt(
hdcMemDC, // 目的DC
0, 0, // 目的DC的 x,y 坐标
width, height, // 目的 DC 的宽高
hdcScreen, // 来源DC
0, 0, // 来源DC的 x,y 坐标
SRCCOPY)) // 粘贴方式
{
DeleteObject(hbmScreen);
DeleteObject(hdcMemDC);
ReleaseDC(NULL, hdcScreen);
return 0;
}

// 获取位图信息并存放在 bmpScreen 中
GetObject(hbmScreen, sizeof(BITMAP), &bmpScreen);

bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = bmpScreen.bmWidth;
bi.biHeight = bmpScreen.bmHeight;
bi.biPlanes = 1;
bi.biBitCount = 32;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;

dwBmpSize = ((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight;

// 在 32-bit Windows 系统上, GlobalAlloc 和 LocalAlloc 是由 HeapAlloc 封装来的
// handle 指向进程默认的堆. 所以开销比 HeapAlloc 要大
hDIB = GlobalAlloc(GHND, dwBmpSize);
lpbitmap = (char *)GlobalLock(hDIB);

// 获取兼容位图的位并且拷贝结果到一个 lpbitmap 中.
GetDIBits(
hdcScreen, // 设备环境句柄
hbmScreen, // 位图句柄
0, // 指定检索的第一个扫描线
(UINT)bmpScreen.bmHeight, // 指定检索的扫描线数
lpbitmap, // 指向用来检索位图数据的缓冲区的指针
(BITMAPINFO *)&bi, // 该结构体保存位图的数据格式
DIB_RGB_COLORS // 颜色表由红、绿、蓝(RGB)三个直接值构成
);


wsprintf(FilePath, "%s\%s.jpg", dirPath, filename);

// 创建一个文件来保存文件截图
hFile = CreateFile(
FilePath,
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);

// 将 图片头(headers)的大小, 加上位图的大小来获得整个文件的大小
dwSizeofDIB = dwBmpSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);

// 设置 Offset 偏移至位图的位(bitmap bits)实际开始的地方
bmfHeader.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER);

// 文件大小
bmfHeader.bfSize = dwSizeofDIB;

// 位图的 bfType 必须是字符串 "BM"
bmfHeader.bfType = 0x4D42; //BM

dwBytesWritten = 0;
WriteFile(hFile, (LPSTR)&bmfHeader, sizeof(BITMAPFILEHEADER), &dwBytesWritten, NULL);
WriteFile(hFile, (LPSTR)&bi, sizeof(BITMAPINFOHEADER), &dwBytesWritten, NULL);
WriteFile(hFile, (LPSTR)lpbitmap, dwBmpSize, &dwBytesWritten, NULL);

// 解锁堆内存并释放
GlobalUnlock(hDIB);
GlobalFree(hDIB);

// 关闭文件句柄
CloseHandle(hFile);

// 清理资源
DeleteObject(hbmScreen);
DeleteObject(hdcMemDC);
ReleaseDC(NULL, hdcScreen);

return 0;
}

编译器一直报错

  • 写回答

4条回答 默认 最新

  • 吉士先生 Java领域新星创作者 2022-08-10 14:42
    关注

    1、库函数拼写错误。如:printf,scanf,等

    2、定义的函数名在调用时,函数名拼写错误

    3、在执行函数时可能函数体本身的问题

    4、其他程序在运行

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 8月21日
  • 已采纳回答 8月13日
  • 创建了问题 8月10日

悬赏问题

  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败