Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Shared Library __declspec(dllexport) __declspec(dllimport) question

Shared Library __declspec(dllexport) __declspec(dllimport) question

Scheduled Pinned Locked Moved Solved C++ Gurus
2 Posts 2 Posters 143 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Online
    R Online
    Redman
    wrote on 20 Mar 2025, 15:06 last edited by Redman
    #1

    Hi,

    im working on restructuring my application to go from statically linked to dynamically.

    Right now I have a Core library which is statically linked into Project library which is statically linked into my Client.exe.

    What I did to make my desired change happen:
    Create core_global.h in the root directory of my Core library, add following code

    #include <QtCompilerDetection>
    #if defined(CORELIB)
    #define CORE_EXPORT Q_DECL_EXPORT
    #else
    #define CORE_EXPORT Q_DECL_IMPORT
    #endif
    

    and use that macro for class/function export.

    Now, when consuming the Core library in my Project library I had some strange behaviour:
    The compiler complained that it can not find core_global.h.
    This makes sense since this file is only present in the Core library.

    Now, how do I go about solving this problem?

    I imagine I have to install the core_global.h in my CMAKE_RUNTIME_OUTPUT_DIRECTORY? But wouldnt this mean that (theoretically) I would have N x_global.h in that folder (assuming I have N shared libraries). And wouldnt that be a problem if a user decides to open that file and change the content?

    Im kinda lost here.

    Thanks :)

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 20 Mar 2025, 17:56 last edited by
      #2

      When you want to include some headers of a library you also must pass the include path to the compiler.
      If you use cmake, use target_include_directories() and add the desired include paths there. Later when you use this library (aka you link them with target_link_libraries()), cmake will automatically add the paths specified.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • R Redman has marked this topic as solved on 21 Mar 2025, 08:34

      2/2

      20 Mar 2025, 17:56

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved