How to link against .a files in Visual Studio 2012

2019-08-08 18:53发布

问题:

I have some static libraries in the form of .a files, and accompanying header (.h) files. How can I tell the linker Visual Studio 2012 Windows Desktop Express to reference these files so that I don't get "unresolved external symbol" errors when I try to build?

回答1:

  • Include the .h header files, and make sure they are present in your project
  • Go to Project Properties > Configuration Properties > C/C++ > General > Additional Include Directories and add the path to the include directory where your header files can be found
  • Go to Project Properties > Configuration Properties > Linker > General > Additional Library Directories and add the path to the lib directory where your .a files can be found
  • Go to Project Properties > Configuration Properties > Linker > Input > Additional Dependencies and add the .a file accurately

Apart from this make sure you are in the correct configuration platform while building (x86 vs x64) and it is same as the one your library uses.



回答2:

As far as I'm aware, you can't. They're usually using a different internal binary format the linker won't be able to understand. In a similar way, MinGW won't be able to use Visual Studio's lib files (except when using an additional tool to convert them).

You'll have to recompile the library from source or obtain library files that are compatible with Visual Studio.