What is proper naming convention for MSVC dlls, static libraries and import libraries

后端 未结 6 517
借酒劲吻你
借酒劲吻你 2021-01-02 03:58

What is standard or \"most-popular\" naming convention for MSVC library builds.

For example, for following platforms library foo has these conventions:<

6条回答
  •  感动是毒
    2021-01-02 04:15

    As mentioned by others, there are no standards, but there are popular conventions. I'm unsure how to unambiguously judge what is the most popular convention. In addition the nomenclature for static vs. import libraries, which you asked about, there is also an analogous distinction between the naming of Release libraries vs. Debug libraries, especially on Windows.

    Both cases (i.e. static vs. import, and debug vs. release) can be handled in one of two ways: different names, or different directory locations. I usually choose to use different names, because I feel it minimizes the chance of mistaking the library type later, especially after installation or other file moving activities.

    I usually use foo.dll and foo.lib for the shared library on Windows, and foo_static.lib for the static library, when I wish to have both shared and static versions. I have seen others use this convention, so it might be the "most popular".

    So I would recommend the following addition to your table:

    Windows/MSVC:

    shared: foo.dll
    import: foo.lib
    static: foo_static.lib
    

    Then in cmake, you could either

    add_library(foo_static STATIC foo.cpp)
    

    or

    add_library(FooStatic STATIC foo.cpp)
    set_target_properties(FooStatic PROPERTIES OUTPUT_NAME "foo_static") 
    

    if for some reason you don't wish to use "foo_static" as the symbolic library name.

提交回复
热议问题