1

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?

2 Answers 2

7
  • 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.

0

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.

7
  • This post seems to suggest it is possible to use MinGW compiled libraries in Visual Studio: stackoverflow.com/questions/9673252/… But it apparently doesn't tell the whole story, because I've tried to duplicate the steps he mentioned and I still have linker errors.
    – duggulous
    Jan 28, 2014 at 17:45
  • There's no way from MinGW's .a files to MSVC's .lib files as far as I know. MinGW/GCC is a lot more tolerant in these regards. Which steps did you try to duplicate?
    – Mario
    Jan 29, 2014 at 8:47
  • I copied the .a files into the project and added them to the configuration under Linker->Input->Additional Dependencies
    – duggulous
    Jan 29, 2014 at 16:36
  • You can't do that. As I mentioned above, Visual Studio (or more specific, Microsoft's linker) won't be able to read typical .a files. You'll need to obtain a precompiled library for MSVC or compile it yourself. As far as I know, MinGW has a command line switch to create compatible libraries (i.e. different binary format), but that's not the default.
    – Mario
    Jan 30, 2014 at 9:17
  • 2
    In fact, you can do that. As it turns out, the only reason I was encountering linker errors is because the .a libs I was using were compiled for 64-bit, while my project is 32-bit. I don't know if MSVC's linker understands all .a files, or just some, but at least in some cases it is possible.
    – duggulous
    Feb 3, 2014 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.