How can I link to a .a file in Visual Studio

  Kiến thức lập trình

I have an application that has been worked on for several decades and I was provided .h and .a files. My program is mainly in C/C++ and when I try to link to these .a files, I get:

Error LINK2019: unresolved external symbol referenced un function
Fatal error LINK1136: invalid or corrupt file.

I’m using Visual Studio 2022 on Windows.

All my other static library files are .libs, but this is an .a file. Is there a way to link to .a static library files?

My .vcxproj files looks like this:

<Link>
    <AdditionalDependancies>...;NewLibrary.a;$(AdditionalDependancies)</AdditionalDependancies>
    ....
</Link>

This is my .props file:

<AdditionalIncludeDirectories>...$(THIRDPARTYLIB)/NewLibraries</AdditionalIncludeDirectories>
<AdditionalLibraryDirectories>...$(THIRDPARTYLIB)/NewLibraries</AdditionalLibraryDirectories>

1

Is your .a file compatible with VS Code tools? If so you can convert it into .lib file by going to the directory where the lib file was and running the below command:

lib /def:NewLibrary.a /out:NewLibrary.lib

If the project is not too long or made completely by you, you can make a .def file that describes the exported functions for that file and then create a .lib file with it.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website Kho Theme wordpress Kho Theme WP Theme WP

LEAVE A COMMENT