Pergunta

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!

Foi útil?

Solução

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.

Outras dicas

If I understand what you are asking, you need to declare a prototype for your function-that-lives-in-a-lib:

Say your lib has:

int Foo(int bar) { ... }

In your "consumer" where you pragma your lib in, you'd need something that states:

extern int Foo(int bar);

or even just:

int Foo(int bar);

Usually, you do this via Header files (.h files), and for libraries, they're usually referred to as "include files"

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top