Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Error Linking Visual Studio DLL to Qt
Forum Updated to NodeBB v4.3 + New Features

Error Linking Visual Studio DLL to Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 378 Views 2 Watching
  • 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.
  • Y Offline
    Y Offline
    yuvalg1987
    wrote on last edited by
    #1

    Hi All,

    I have written a project in visual studio that I would like to use within Qt as a dll. The project cosists of a class and several additional c++ files that are not part of the class. Within the class I use the functions that are found in the additional files.

    Ideally I would like to export only the class and use it as a dll within Qt but I'm encountering some difficulries.

    I've manged to export/link/include all the relevent files from visual studio to Qt but every time the class uses one of the functions found in the additinal files the program crashes. Initially, I thought there must be something wrong with my dll but it works perfectly when I try to load it to a similar program in visual studio.

    I use MVSC in both Visual Studio and Qt, and used __dllexport only on the class defenition itself. Any ideas what I might be doing wrong?

    Thanks in advance,
    Yuval

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      The export/import declaration is a bit more complex than that.

      Please take a look at the creating shared library guide in Qt's documentation. The concept applies also to standard C++ projects with some minor adjustments.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      4
      • Y Offline
        Y Offline
        yuvalg1987
        wrote on last edited by
        #3

        Thanks for the quick reply. I've tried adding the following lines to all the h files in my VS project:
        #ifdef PROJECT_LIB
        #define PROJECT_EXPORT __declspec(dllexport)
        #else
        #define PROJECT_EXPORT __declspec(dllimport)
        #endif

        in addition, I've added the following line to my Qt pro files:
        DEFINES += PROJECT_LIB

        I'm still geting the same behavior. Any advice?

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @yuvalg1987 said in Error Linking Visual Studio DLL to Qt:

          in addition, I've added the following line to my Qt pro files:

          You must define PROJECT_LIB only when building the lib, not when using it

          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
          3
          • Y Offline
            Y Offline
            yuvalg1987
            wrote on last edited by
            #5

            Ok. not sure what I did exactly but it works! Thanks for the help!

            1 Reply Last reply
            1

            • Login

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