Henricus V.
Henricus V.

Reputation: 948

How to use libpng in Visual Studio?

I am using boost generic image library and it requires libpng. I built libpng and obtained the files libpng.lib, zlib.lib and libpngd.lib. When I tried to compile my project, Visual Studio gives a fatal error

fatal error LNK1120: 21 unresolved externals

with a bunch of unresolved external symbols like _png_set_sig_bytes and _png_read_row. What's going on here and how to solve it?

Upvotes: 3

Views: 8960

Answers (2)

Mark Aven
Mark Aven

Reputation: 365

So this is coming from a complete simple minded moron so maybe this'll be helpful....it took me a little while to grasp. Basically, you're downloading the source code. That means, that you have to be the one to compile the source code.

Windows can compile programs that are written in C in the command prompt. You have to build the program, and it spits out a .dll or a .lib file. That or those are the files that you link to visual studio application.

You set dependencies to the header files which is usually like the source codes root folder or wherever all those .h files are.

You then set the linker to link to the .dll or .lib file(s). In Boost C++'s case, you need to link to a 'lib' folder.

I think what you need is to go over and completely grasp the basics. Here's a link from Microsoft on how Windows can compile C programs from the command prompt: https://learn.microsoft.com/en-us/cpp/build/walkthrough-compile-a-c-program-on-the-command-line?view=vs-2019

Upvotes: 0

paulsm4
paulsm4

Reputation: 121649

From MSDN:

https://msdn.microsoft.com/en-us/library/ba1z7822.aspx?f=255&MSPPError=-2147217396

To add .lib files as linker input in the development environment

    Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.

    Click the Linker folder.

    Click the Input property page.

    Modify the Additional Dependencies property.

You must do this; explicitly specifying "libpng.lib", "zlib.lib" and "libpngd.lib" in your .exe's link command.

Upvotes: 1

Related Questions