添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams
  • Option 1: Decorate the API with __declspec(dllexport) .
  • Option 2: set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) .
  • We go for option 2, since it seems much easier, and leaves our sources intact. Works like a charm: our application compiles and gets linked with the library dll.

    However, it ensures only the export of classes and functions. What needs to be done to export global variables? Like in:

    lib_source.cpp:
        int my_secret;
    app.cpp:
        extern int my_secret;
      

    For global data symbols, __declspec(dllimport) must still be used when compiling against the code in the .dll.

    src: https://cmake.org/cmake/help/latest/prop_tgt/WINDOWS_EXPORT_ALL_SYMBOLS.html

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.