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

  • SEARCH
  • Home
  • 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 4271424
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:26:26+00:00 2026-05-21T07:26:26+00:00

I can’t quite figure out where there is a mistake. I am creating a

  • 0

I can’t quite figure out where there is a mistake. I am creating a DLL and then using it in a C++ console program (Windows 7, VS2008). But I get LNK2019 unresolved external symbol when trying to use the DLL functions.

First the export:

#ifndef __MyFuncWin32Header_h
#define __MyFuncWin32Header_h

#ifdef MyFuncLib_EXPORTS
#  define MyFuncLib_EXPORT __declspec(dllexport)
# else
#  define MyFuncLib_EXPORT __declspec(dllimport)
# endif  

#endif

This is one header file I then use in:

#ifndef __cfd_MyFuncLibInterface_h__
#define __cfd_MyFuncLibInterface_h__

#include "MyFuncWin32Header.h"

#include ... //some other imports here

class  MyFuncLib_EXPORT MyFuncLibInterface {

public:

MyFuncLibInterface();
~MyFuncLibInterface();

void myFunc(std::string param);

};

#endif

Then there is the dllimport in the console program, which has the DLL included in the Linker->General->Additional Library Directories:

#include <stdio.h>
#include <stdlib.h>
#include <iostream>


__declspec( dllimport ) void myFunc(std::string param);


int main(int argc, const char* argv[])
{
    std::string inputPar = "bla";
    myFunc(inputPar); //this line produces the linker error
}

I can’t figure out what’s going wrong here; it must be something really simple and fundamental.

  • 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-05-21T07:26:26+00:00Added an answer on May 21, 2026 at 7:26 am

    You’re exporting a class member function void MyFuncLibInterface::myFunc(std::string param); but trying to import a free function void myFunc(std::string param);

    Make sure you #define MyFuncLib_EXPORTS in the DLL project. Make sure you #include "MyFuncLibInterface.h" in the console app without defining MyFuncLib_EXPORTS.

    The DLL project will see:

    class  __declspec(dllexport) MyFuncLibInterface {
    ...
    }:
    

    And the console project will see:

    class  __declspec(dllimport) MyFuncLibInterface {
    ...
    }:
    

    This allows your console project to use the class from the dll.

    EDIT: In response to comment

    #ifndef FooH
    #define FooH
    
    #ifdef BUILDING_THE_DLL
    #define EXPORTED __declspec(dllexport)
    #else
    #define EXPORTED __declspec(dllimport)
    #endif
    
    class EXPORTED Foo {
    public:
      void bar();
    };
    
    
    #endif
    

    In the project which actually implements Foo::bar() BUILDING_THE_DLL must be defined. In the project which tries to use Foo, BUILDING_THE_DLL should not be defined. Both projects must #include "Foo.h", but only the DLL project should contain "Foo.cpp"

    When you then build the DLL, the class Foo and all its members are marked as “exported from this DLL”. When you build any other project, the class Foo and all its members are marked as “imported from a DLL”

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can I authenticate with just Google account username and password instead of using OAuth?
Can anyone explain to me why this program: for(float i = -1; i <
Can any one help me in sorting this out in sed/awk/perl Input file Start
Can anyone help me trying to find out why this doesn't work. The brushes
Can I run VLD extension over IIS or Apache that works over windows? and
Can someone please tell me is there a way to solve difference equation e.g:
Can anyone advise on the correct FFT to be using (Real or Complex)? I
can I get the value of a variable declared in a procedure then use
Can someone please explain (preferably using plain english) how std::flush works? What is it?

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.