Home > Software engineering >  No .lib file generated after building tiny C static library project
No .lib file generated after building tiny C static library project

Time:09-08

I decided on adding a tiny extra project to my visual studio solution which includes only a single header file(for now) with a mutex which allows only 1 thread to output to the console at a time. Since this is a functionality which all of my projects in my solution will need so I thought it will be best to add a separate project for it and add references to it on the other projects.

So I created an empty project named Commons, then added an header file logger_mutex.h and wrote the following code inside it.

#pragma once

#ifdef _DEBUG
#include <mutex>
std::mutex loggerMutex;
#endif

I changed the project type in properties from Application(.exe) to Static Library (.lib). Then I added the include path to this file in the other project properties. Also I added this Commons project as a reference to all my other projects. But now when I try to build the solution it gave the error LINK1104 cannot open file ../path/to/my/output/directory/Commons.lib

I investigated on the output directory and there was no file in there named Commons.lib. I tried rebuilding the Commons project separately, and even though visual studio said it built successfully I did not see the Commons.lib file appear on the output directory.

I tried it even without the other projects, in a completely different solution. It still did not generate any .lib file in the output directory. I think this should be verifiable as well.

So what am I missing here, is there some kind of minimum requirement needed to have to get a .lib output file generated? Is my code too small to generate a .lib output? I am using Visual Studio 2022.

CodePudding user response:

Add one empty .cpp file in your lib project and a lib will be generated. But as far as I am concerned, it will be better to #include the logger_mutex.h to other project's pch.h instead as a library.

  • Related