C++ 错误:LNK1120:9个未解析的外部
我正在尝试使用以下代码将bmp图像转换为png图像:C++ 错误:LNK1120:9个未解析的外部,c++,C++,我正在尝试使用以下代码将bmp图像转换为png图像: #define WIN32_LEAN_AND_MEAN #define _CRT_SECURE_NO_DEPRECATE #include <png.h> #include <stdlib.h> #include <stdio.h> #include <stdint.h> void GetDesktopResolution(int& horizontal, int& vert
#define WIN32_LEAN_AND_MEAN
#define _CRT_SECURE_NO_DEPRECATE
#include <png.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
void GetDesktopResolution(int& horizontal, int& vertical)
{
RECT desktop;
// Get a handle to the desktop window
const HWND hDesktop = GetDesktopWindow();
// Get the size of screen to the variable desktop
GetWindowRect(hDesktop, &desktop);
// The top left corner will have coordinates (0,0)
// and the bottom right corner will have coordinates
// (horizontal, vertical)
horizontal = desktop.right;
vertical = desktop.bottom;
}
typedef struct _RGBPixel {
uint8_t blue;
uint8_t green;
uint8_t red;
} RGBPixel;
/* Structure for containing decompressed bitmaps. */
typedef struct _RGBBitmap {
RGBPixel *pixels;
size_t width;
size_t height;
size_t bytewidth;
uint8_t bytes_per_pixel;
} RGBBitmap;
/* Returns pixel of bitmap at given point. */
#define RGBPixelAtPoint(image, x, y) \
*(((image)->pixels) + (((image)->bytewidth * (y)) \
+ ((x) * (image)->bytes_per_pixel)))
/* Attempts to save PNG to file; returns 0 on success, non-zero on error. */
int save_png_to_file(RGBBitmap *bitmap, const char *path)
{
FILE *fp = fopen(path, "wb");
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
size_t x, y;
png_uint_32 bytes_per_row;
png_byte **row_pointers = NULL;
if (fp == NULL) return -1;
/* Initialize the write struct. */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
fclose(fp);
return -1;
}
/* Initialize the info struct. */
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
png_destroy_write_struct(&png_ptr, NULL);
fclose(fp);
return -1;
}
/* Set up error handling. */
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
return -1;
}
/* Set image attributes. */
png_set_IHDR(png_ptr,
info_ptr,
bitmap->width,
bitmap->height,
8,
PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
/* Initialize rows of PNG. */
bytes_per_row = bitmap->width * bitmap->bytes_per_pixel;
png_malloc(png_ptr, bitmap->height * sizeof(png_byte *));
for (y = 0; y < bitmap->height; ++y) {
uint8_t *row = (uint8_t *)png_malloc(png_ptr, sizeof(uint8_t)* bitmap->bytes_per_pixel);
row_pointers[y] = (png_byte *)row;
for (x = 0; x < bitmap->width; ++x) {
RGBPixel color = RGBPixelAtPoint(bitmap, x, y);
*row++ = color.red;
*row++ = color.green;
*row++ = color.blue;
}
}
/* Actually write the image data. */
png_init_io(png_ptr, fp);
png_set_rows(png_ptr, info_ptr, row_pointers);
png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
/* Cleanup. */
for (y = 0; y < bitmap->height; y++) {
png_free(png_ptr, row_pointers[y]);
}
png_free(png_ptr, row_pointers);
/* Finish writing. */
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
return 0;
}
int main()
{
RGBBitmap rgbbitmap;
int w, h;
GetDesktopResolution(w, h);
rgbbitmap.height = h;
rgbbitmap.width = w;
rgbbitmap.bytes_per_pixel = 1;
rgbbitmap.bytewidth = w / 100;
RGBPixel rgbpixel;
rgbpixel.blue = 100;
rgbpixel.green = 100;
rgbpixel.red = 100;
rgbbitmap.pixels = &rgbpixel;
save_png_to_file(&rgbbitmap, "abc.bmp");
return 0;
}
#定义WIN32_LEAN_和_MEAN
#定义\u CRT\u SECURE\u NO\u弃用
#包括
#包括
#包括
#包括
void GetDesktopResolution(整数和水平、整数和垂直)
{
矩形桌面;
//获取桌面窗口的句柄
const HWND hDesktop=GetDesktopWindow();
//获取可变桌面的屏幕大小
GetWindowRect(hDesktop和桌面);
//左上角将有坐标(0,0)
//右下角有坐标
//(水平、垂直)
水平=桌面。右;
垂直=桌面。底部;
}
typedef结构\u RGBPixel{
uint8_t蓝;
uint8_t绿色;
uint8_t红色;
}RGB像素;
/*用于包含解压缩位图的结构*/
类型定义结构_RGBBitmap{
RGB像素*像素;
尺寸和宽度;
尺寸和高度;
大小字节宽度;
每像素8字节;
}RGBBitmap;
/*返回给定点位图的像素*/
#定义RGB像素点(图像,x,y)\
*((图像)->像素)+((图像)->字节宽度*(y))\
+((x)*(图像)->每像素字节数)
/*尝试将PNG保存到文件;成功时返回0,错误时返回非零*/
int save_png_to_文件(RGBBitmap*位图,const char*路径)
{
文件*fp=fopen(路径,“wb”);
png_structp png_ptr=NULL;
png_infop info_ptr=NULL;
尺寸x,y;
png每行32字节;
png_字节**行指针=NULL;
if(fp==NULL)返回-1;
/*初始化写结构*/
png_ptr=png_create_write_struct(png_LIBPNG_VER_STRING,NULL,NULL);
如果(png_ptr==NULL){
fclose(fp);
返回-1;
}
/*初始化信息结构*/
info_ptr=png_create_info_struct(png_ptr);
if(info_ptr==NULL){
png_destroy_write_struct(&png_ptr,NULL);
fclose(fp);
返回-1;
}
/*设置错误处理*/
if(setjmp(png_jmpbuf(png_ptr))){
png_destroy_write_struct(&png_ptr和&info_ptr);
fclose(fp);
返回-1;
}
/*设置图像属性*/
png\U set\U IHDR(png\U ptr,
信息,
位图->宽度,
位图->高度,
8.
PNG_颜色_类型_RGB,
PNG\u交错\u无,
PNG\压缩\类型\默认值,
PNG_过滤器_类型_默认值);
/*初始化PNG的行*/
每行字节数=位图->宽度*位图->每像素字节数;
png_malloc(png_ptr,位图->高度*大小(png_字节*);
对于(y=0;yheight;++y){
uint8_t*行=(uint8_t*)png_malloc(png_ptr,sizeof(uint8_t)*位图->每像素字节数);
行指针[y]=(png字节*)行;
对于(x=0;xwidth;++x){
RGB像素颜色=RGB像素点(位图,x,y);
*row++=color.red;
*row++=color.green;
*row++=color.blue;
}
}
/*实际写入图像数据*/
png_init_io(png_ptr,fp);
png_设置_行(png_ptr、信息_ptr、行指针);
png_write_png(png_ptr,info_ptr,png_TRANSFORM_IDENTITY,NULL);
/*清理*/
对于(y=0;yheight;y++){
png_-free(png_-ptr,行指针[y]);
}
png_免费(png_ptr,行指针);
/*写完*/
png_destroy_write_struct(&png_ptr和&info_ptr);
fclose(fp);
返回0;
}
int main()
{
RGBBitmap RGBBitmap;
int w,h;
GetDesktopResolution(w,h);
rgbbitmap.height=h;
rgbbitmap.width=w;
rgbbitmap.bytes_/_像素=1;
rgbbitmap.bytewidth=w/100;
RGB像素RGB像素;
rgbpixel.blue=100;
rgbpixel.green=100;
rgbpixel.red=100;
rgbbitmap.pixels=&rgbpixel;
将_png_保存到_文件(&rgbbitmap,“abc.bmp”);
返回0;
}
执行此代码会触发以下错误:
LNK1120:9个未解析的外部
LNK2019:未解析的外部符号“\u png\u创建\u信息\u结构”在函数“int\uu cdecl将\u png\u保存到\u文件(struct\u RGBBitmap*,char const*)”中引用(?将\u png\u保存到\u文件@YAHPAU\u RGBBitmap@@PBD@Z)
LNK2019:未解析的外部符号“\u png\u create\u write\u struct”在函数“int\uu cdecl将\u png\u保存到\u文件(struct\u RGBBitmap*,char const*)”中引用(?将\u png\u保存到\u文件@YAHPAU\u RGBBitmap@@PBD@Z)
LNK2019:函数“int\uu cdecl将png保存到文件(struct\u RGBBitmap*,char const*)”中引用的未解析外部符号\u png\u destroy\u write\u struct(?将png保存到文件@YAHPAU\u RGBBitmap@@PBD@Z)
LNK2019:未解析的外部符号在函数“int\uu cdecl save\u png\u to_file(struct\u RGBBitmap*,char const*)”中引用(?save_png\u to_file@@YAHPAU\RGBBitmap@@PBD@Z)
LNK2019:未解析的外部符号“\u png\u init\u io在函数“int\uu cdecl将\u png\u保存到\u文件(struct\u RGBBitmap*,char const*)”中引用”(?将\u png\u保存到\u文件@YAHPAU\u RGBBitmap)@@PBD@Z)
LNK2019:未解析的外部符号“\u png\u malloc在函数“int\uu cdecl save\u png\u to_file(struct\u RGBBitmap*,char const*)”中引用”(?save_png\u to_file@@YAHPAU\u RGBBitmap)@@PBD@Z)
LNK2019:未解析的外部符号\u png\u集合\u IHDR在函数“int\uu cdecl将png\u保存到\u文件(struct\u RGBBitmap*,char const*)”中引用(?将png\u保存到\u文件@YAHPAU\u RGBBitmap)@@PBD@Z)
LNK2019:未解析的外部符号“\u png\u set\u函数“int\uu cdecl保存\u png\u到\u文件(struct\u RGBBitmap*,char const*)”中引用的行”(?保存\u png\u到\u文件@YAHPAU\u RGBBitmap)@@PBD@Z)
LNK2019:未解析的外部符号“\u png\u write\u png”在函数“int\uu cdecl保存\u png\u到\u文件(struct\u RGBBitmap*,char const*)”中引用(?保存\u png\u到\u文件@YAHPAU\u RGBBitmap@@PBD@Z)
我无法找到如何修复这些错误。有什么好建议吗
我目前正在Windows 7 SP1平台上使用Visual Studio Ultimate 2013
非常感谢 我想,你没有链接你的库,只是包含了标题。你是怎么做的 如果没有,就没有全票