Creating a library project in Visual Studio 2022

thebluetropics 1,046 Reputation points
2022-10-12T07:59:40.06+00:00

Assume I have a two project in a solution: mylib and mylib-test

There is two files inside mylib: mylib.h and mylib.cpp.
And one main.cpp file inside mylib-test project. main.cpp include files from mylib, such as mylib.h.

I want to mylib-test is the only that will be run after build.
For that purpose, I don't want mylib project contains any entry point (e.g WinMain, wWinMain, main`).
But it fails on the build process, it says, missing link (that is, the main function is missing).

Of course, I don't want a main function is inside my library project, as it is a library...

I am using Empty Project as the template for mylib and Windows Desktop Project for mylib-test

Developer technologies Visual Studio Setup
Developer technologies C++
Developer technologies Visual Studio Other
0 comments No comments
{count} votes

Accepted answer
  1. YujianYao-MSFT 4,296 Reputation points Microsoft External Staff
    2022-10-12T08:18:48.93+00:00

    Hi @thebluetropics ,

    Usually, lib projects don't need main(), so we don't need to debug the lib, just let it pass the build. About how to create and use lib I recommend you read this document carefully, it will help you.

    Best regards,

    Elya


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. RLWA32 49,536 Reputation points
    2022-10-12T08:14:18.44+00:00

    In the project property page for mylib make sure that the configuration is set to build a static library. See general-property-page-project for configuration type.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.