0

I'm trying to use this code to convert bmp to png. Here is the full lib's content. But, doing that triggers the following errors:

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

Here is the main code:

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]);
}

Any brilliant idea to fix this, please?

Thanks a lot!

user3472134
  • 11
  • 1
  • 4
  • 3
    Where is `lodepng` defined and how are you including it? What commands are you using to compile and link the program? I'm going to guess that this library requires you to link it in but you haven't given the command to the linker. If you are using `gcc` or similar you need give a `-lmy_library_name` type command to the linker. – shuttle87 Mar 28 '14 at 13:44
  • Here is [lodepng.h](http://lpi.googlecode.com/svn/trunk/lodepng.h). I've just downloaded these two files, created a new C++ project using Visual Studio Ultimate 2013 on Windows 7 SP1 plateform, added them into the project, and bluit it. – user3472134 Mar 28 '14 at 13:47
  • You need to provide ALL of your code that relates to `loadpng` in the file that contains the `main` function. – shuttle87 Mar 28 '14 at 13:49
  • @shuttle87: No, _absolutely not_. A minimal testcase, yes. – Lightness Races in Orbit Mar 28 '14 at 13:50
  • You said you downloaded two files, but you linked us to only one. Where is the file containing definitions for the library's functions? – Lightness Races in Orbit Mar 28 '14 at 13:51
  • @LightnessRacesinOrbit, I've linked the two files, ;-) First the first posted link and then the comment posted link. And, I've provided the full cpp/h files provided by the website admin. So to summirize, I'm using `lodepng.h` file and `example_bmp2png.cpp` that I've downloaded from [here](http://lodev.org/lodepng/) – user3472134 Mar 28 '14 at 13:55
  • Oh yes, so you did. Well, the functions are not defined in either of those files, so you're missing one. Looks like you forgot `lodepng.cpp`. – Lightness Races in Orbit Mar 28 '14 at 13:56
  • @LightnessRacesinOrbit, you're right xD. OMG! Shame on me xD – user3472134 Mar 28 '14 at 14:00
  • I'm quite frequently right ;) – Lightness Races in Orbit Mar 28 '14 at 14:00
  • @LightnessRacesinOrbit, thank you so much! Would you want to post your answer? Or, may I delete this? – user3472134 Mar 28 '14 at 14:23
  • Oh go on then I'll answer it why not – Lightness Races in Orbit Mar 28 '14 at 14:24

1 Answers1

2

You have the library's header and some abstract example code, but you're missing the "meat" of the library.

In short, you forgot lodepng.cpp. It's available on the developer's website and should be added to your project.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055