Visual Studio 2019 won't to create .lib file in .dll project

2024-02-15T15:38:55.66+00:00

Hi all,

I'm learning to create .dll files. I started from the following page: https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=msvc-170. I was able to configure Visual Studio correctly and I successfully created MathLibrary.dll file.

However, when i compile MathLibrary project, the .lib file isn't create. My code is exactly the same in the page. I have searched online for a solution, but I have not found one that works.

Can someone help me?

Thank you,

Developer technologies | Visual Studio | Other
{count} votes

1 answer

Sort by: Most helpful
  1. WilliamDymitriosFrancescoGrimaldi-6600 0 Reputation points
    2024-02-15T17:10:42.4566667+00:00

    Hi all,

    thank you for your help but i found a solution by myself. I explain for future leaners. I made three mistake:

    1. I change the header and cpp files name to "MathLibrary-William" whithout changing these very first lines of code:
    #ifdef MATHLIBRARY_EXPORTS
    #define MATHLIBRARY_API __declspec(dllexport)
    #else
    #define MATHLIBRARY_API __declspec(dllimport)
    #endif
    
          So the precompiler didn't find 
    
    __declspec(dllexport)
    
         directive and couldn't generate .lib file;
    
    1. When i created "MathLibrary-William.h" and "MathLibrary-William.cpp" files, I didn't add it in my project correct. We must click to File->Move to->"Project name";
    2. #define directive can't have a - in their name.

    I hope these errors can help someone.

    0 comments No comments

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.