错误:LNK1120:3个未解析的外部

时间:2014-03-28 13:43:18

标签: c++

我正在尝试使用this code将bmp转换为png。 Here is the full lib's content。但是,这样做会触发以下错误:

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)" (?encode@lodepng@@YAIAAV?$vector@EV?$allocator@E@std@@@std@@ABV23@IIW4LodePNGColorType@@I@Z) 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 &)" (?load_file@lodepng@@YAXAAV?$vector@EV?$allocator@E@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@@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 &)" (?save_file@lodepng@@YAXABV?$vector@EV?$allocator@E@std@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@@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]);
}

有什么好主意可以解决这个问题吗?

非常感谢!

1 个答案:

答案 0 :(得分:2)

你有图书馆的标题和一些抽象的示例代码,但是你错过了图书馆的“肉”。

简而言之,您忘记了lodepng.cpp。它可以在开发人员的网站上找到,并且应该添加到您的项目中。