gpt4 book ai didi

c++ - 为什么使用 GetPixel 会导致 "undefined reference"?

转载 作者:可可西里 更新时间:2023-11-01 09:35:26 28 4
gpt4 key购买 nike

#include <iostream>
#include <windows.h>
#include <string>
#include <ctime>
#include<stdio.h>

using namespace std;

int main()
{
HDC dc = GetDC(NULL);
COLORREF color = GetPixel(dc, 10, 10);
ReleaseDC(NULL, dc);
cout << color;

return 0;
}

有一个错误说:

[Linker error] undefined reference to `GetPixel@12'   
ld returned 1 exit status
[Build Error] [Project1.exe] Error 1

我正在使用 Dev-C++ 编译器

最佳答案

您需要将Gdi32.lib 添加到您的依赖列表中。 GetPixel() 函数不在默认库中。

编辑:

在 Visual Studio 中,您可以像这样添加依赖项:

菜单:项目 -> 属性 -> 配置属性 -> 链接器 -> 输入

“附加依赖项”选项将如下所示:

kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib; odbccp32.lib;%(AdditionalDependencies)

添加 Gdi32.lib 到它。

关于c++ - 为什么使用 GetPixel 会导致 "undefined reference"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7493961/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com