0
我試圖使用this code將bmp轉換爲png。 Here is the full lib's content。但是,這樣做會觸發以下錯誤:錯誤:LNK1120:3個未解析的外部設備
LNK1120: 3 unresolved externals
----- LNK2019: unresolved external symbol "unsigned int __cdecl lodepng::encode(class std::vector<unsigned char,class std::allocator<unsigned char> > &,class std::vector<unsigned char,class std::allocator<unsigned char> > const &,unsigned int,unsigned int,enum LodePNGColorType,unsigned int)" ([email protected]@@[email protected][email protected]@[email protected]@@[email protected]@[email protected]@@[email protected]) referenced in function _main
----- LNK2019: unresolved external symbol "void __cdecl lodepng::load_file(class std::vector<unsigned char,class std::allocator<unsigned char> > &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" ([email protected]@@[email protected][email protected]@[email protected]@@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) referenced in function _main
----- LNK2019: unresolved external symbol "void __cdecl lodepng::save_file(class std::vector<unsigned char,class std::allocator<unsigned char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" ([email protected]@@[email protected][email protected]@[email protected]@@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) referenced in function _main
下面是主要代碼:
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cout << "Please provice input PNG and output BMP file names" << std::endl;
return 0;
}
std::vector<unsigned char> bmp;
lodepng::load_file(bmp, argv[1]);
std::vector<unsigned char> image;
unsigned w = 1600, h = 900;
unsigned error = decodeBMP(image, w, h, bmp);
if (error)
{
std::cout << "BMP decoding error " << error << std::endl;
return 0;
}
std::vector<unsigned char> png;
error = lodepng::encode(png, image, w, h);
if (error)
{
//std::cout << "PNG encoding error " << error << ": " << lodepng_error_text(error) << std::endl;
return 0;
}
lodepng::save_file(png, argv[2]);
}
任何高招解決這個問題,好嗎?
非常感謝!
lodepng定義在哪裏,你如何包含它?你用什麼命令來編譯和鏈接程序?我會猜測這個庫需要你鏈接它,但你還沒有把命令給鏈接器。如果你使用'gcc'或類似的命令,你需要給鏈接器一個'-lmy_library_name'類型的命令。 – shuttle87
這是[lodepng.h](http://lpi.googlecode.com/svn/trunk/lodepng.h)。我剛剛下載了這兩個文件,在Windows 7 SP1平臺上使用Visual Studio Ultimate 2013創建了一個新的C++項目,並將它們添加到項目中,並將其添加爲藍色。 – user3472134
您需要在包含'main'函數的文件中提供與'loadpng'相關的所有代碼。 – shuttle87