Using a .lib in visual studio 2012 (C++)

knoxaramav2 picture knoxaramav2 · Feb 8, 2013 · Viewed 10k times · Source

I have a .lib static library. I've linked it under the Linker settings 'Additional Library Directories', and 'Additional Dependencies', as well as using pragma comment (lib, "mylib").. And all of that compiles fine.

What I'm asking, and I can only seem to find linking solutions when I look, is how to actually use the functions in it. If I had a function 'MyFunc' referenced in my static library, how could I call it? Visual Studio does not currently recognize any namespaces or functions defined in the library.

Thanks!

Answer

Nemanja Boric picture Nemanja Boric · Feb 8, 2013

You need to get header file for that library, which is usually shipped with the library. After that, you need to include it in your file where you want to use functions from it, and to call functions using declared prototypes.

Your compiler needs to know about prototypes of the functions - because it can't read/parse lib file - that is linker's job.