Visual Studio not creating .lib file for static library build

Viewed 1175

Windows 10

Microsoft Visual Studio Community 2019 Version 16.7.3

In my solution, there is project A, B, and C. A's and B's configuration types are set to Static Library (.lib). A, B, and C all have their output directory set to $(SolutionDir)bin\builds$(Configuration)-$(Platform)$(ProjectName)\

The output file is the default $(OutDir)$(TargetName)$(TargetExt) for all three.

C's configuration type is Application (.exe). It's additonal include directories are set to $(SolutionDir)A\src;$(SolutionDir)B\src

A and B's src folder have A.h and B.h file respectively.

C has it's references set to have A and B.

When I (re)build C, it succeeds in building A and B, but then gets a LNK1104 error saying it can't open the lib file that is bin\builds\Debug-x64\A\A.lib. The reason it can't open it is because the file doesn't exist. I clean the solution and rebuild A, and it says it succeeds, but despite that, not .lib file is created. I searched everywhere in the solution with File Explorer and there isn't a single .lib file.

Any help would be greatly appreciated.

2 Answers

I suggest that you could refer to Microsoft Docs about lnk1104.

  • You may see this error if filename doesn't exist yet when the linker tries to access it. It can happen when one project depends on another in the solution, but the projects build in the wrong order. To fix this issue, make sure your project references are set in the project that uses the file. Then the missing file gets built before it's required.

Then, you could refer to the link for more information about Consuming libraries and components.

If your static library project is being built in the same solution:

  1. #include the header file(s) for the static library using quotation marks. In a typical solution the path will start with . IntelliSense will help you find it.../<library project name>
  2. Add a reference to the static library project. Right-click on References under the application project node in Solution Explorer and choose Add Reference.

I had same problem as well a similar project structure as yours. This is what I have done and the problem was resolved... Go to, Linker -> General -> Use Library Dependency Inputs, then check Yes

Related