Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9222627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:52:37+00:00 2026-06-18T03:52:37+00:00

My problem is remarkably similar to this one : A class in a DLL

  • 0

My problem is remarkably similar to this one: A class in a DLL has a static member. In this case, the static member is of Type QString (a QT type) and provides a name for the class. I provide the normal export on class level: __declspec(dllexport).

When I link the DLL with my class to another project and try to compile it, I get an “unresolved external symbol” error for the static data. I verified two things:

  1. Dumpbin definitely reports the static data member to be exported by compiled DLL.
  2. Actually, the static data member seems not to be used in the application which reports the error.

HEADER file (.h) in DLL is:

class __declspec(dllexport) MyClass {
public: 
   virtual ~MyClass();
   static const QString JUST_A_NAME;    
};

IMPLEMENTATION file (.cpp) in DLL is:

#include "MyClass.h"

MyClass::~MyClass() { }
const QString MyClass::JUST_A_NAME("call_me_al");

In contrast to already mentioned post, I avoided methods to be inline, e.g. implementation is obviously not in the header. The type, QString (see line 83 ff.), contains several inlines itself. May that cause the error?

EDIT: I added an import statement in the header of my application. It is located before any includes.
HEADER file (.h) in APPLICATION is:

class __declspec(dllimport) MyClass {
public: 
   virtual ~MyClass();
   static const QString JUST_A_NAME;    
};

The error remains the same:

error LNK2001: non resolved external symbol ""public: static class QString const MyClass::JUST_A_NAME" (?JUST_A_NAME@MyClass@@2VQString@@B)". <name of .obj file from application>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:52:38+00:00Added an answer on June 18, 2026 at 3:52 am

    In your application header file you need to do two things.

    1. When exporting, declare the definition __declspec(dllexport)
    2. When importing, declare the definition __declspec(dllimport)

    You obviously cannot do them both at the same time.

    What you have to do is define a macro like this:

    #ifdef __COMPILING_MYLIB
    #define MYLIBAPI __declspec(dllimport)
    #else
    #define MYLIBAPI __declspec(dllexport)
    #endif
    

    Then declare your exports like this:

    // mylib.h
    class MYLIBAPI MyClass {
    public: 
       virtual ~MyClass();
       static const QString JUST_A_NAME;    
    };
    

    Then, when compiling MYLIB, you pass -D__COMPLING_MYLIB to the compiler, which triggers the #if above.

    That way, when compiling the library itself, the header file declares things as exports, but when compiling things which will use the library, they are declared as imports.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I've written State Machine for my android application. It is separate class, extension
Problem: I have two array where one produce a category and the second produce
Problem occured when i tried to display xml data that has been taken by
Problem: Need to bind a strongly typed model which has a Gender as enum
Problem Not solved although one answer was accepted: We are working to get Jonah's
When user logs in. I Open connection 'conn' which is a public static member
I have a weird problem in some JavaScript code that's a part of one
PROBLEM SOLVED. Special thanks to Andrew Noyes for explaining its not a class but
Problem: I have a large database table (~500k records) which has a list of
Problem I'm using this implementation of a CSS sticky footer. It does: html,body{ height:100%;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.