0

I am learning cmake on windows.
I read and run this example so that I can build both static and shared libraries from one visual studio project.
I found this command:

add_library(math SHARED ${MATH_SOURCES} ${SIMPLE_FUNCTION_SOURCES} ${ADVANCED_FUNCTION_SOURCES})

According to my understanding, this command is building shared library. Also, from here, if I want to build static and shared library, I have to do it by two projects.

So, why the first example I used can build both libraries from one Visual Studio project?

Edit
Thanks for Florian, the key point is in MathExports.h. To let people easier to see, I put the file here:

#ifndef MathExports_h
#define MathExports_h

#ifdef _WIN32
    #ifdef math_EXPORTS
        #define  MATH_EXPORT __declspec( dllexport )
    #else
        #define  MATH_EXPORT __declspec( dllimport )
    #endif
#else
    #define    MATH_EXPORT
#endif

#endif // MathExports_h
Community
  • 1
  • 1
sflee
  • 1,659
  • 5
  • 32
  • 63

1 Answers1

2

The linked example doesn't build a standalone static math library. It does have "exports" (see MathExports.h) and therefore it's generating an additional import .lib (which references the build shared library).

This import library is used when you are "linking" against the DLL.

You can use

dumpbin /symbols math.lib

to see the references in math.lib to math.dll.

References

Community
  • 1
  • 1
Florian
  • 39,996
  • 9
  • 133
  • 149