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 8491637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:29:06+00:00 2026-06-10T22:29:06+00:00

For simplicity, I’ve placed both DLL_TUTORIAL.dll with header MathFuncsDll.h in the root folder C:\

  • 0

For simplicity, I’ve placed both DLL_TUTORIAL.dll with header MathFuncsDll.h in the root folder C:\ .

Then, created the empty project, setting

Configuration Properties->Linker->Input->Delay Loaded Dll’s

to

C:\DLL_TUTORIAL.dll;%(DelayLoadDLLs)

and

Configuration Properties->VC++ Directories->Include Directories

to

C:\;$(IncludePath)

Complier commands:

/Zi /nologo /W3 /WX- /O2 /Oi /Oy- /GL /D “_MBCS” /Gm- /EHsc /MT /GS
/Gy /fp:precise /Zc:wchar_t /Zc:forScope
/Fp”Release\clean_rough_draft.pch” /Fa”Release\” /Fo”Release\”
/Fd”Release\vc100.pdb” /Gd /analyze- /errorReport:queue

This project contains only the file with main.

main.cpp

#include <Windows.h>
#include <iostream>
#include "MathFuncsDll.h"

using namespace MathFuncs;
using namespace std;

int main()
{
    std::cout<< MyMathFuncs<int>::Add(5,10)<<endl;

    system("Pause");
    return 0;
}

Dll has been compiled successfully in different solution.

MathFuncsDll.h

namespace MathFuncs
{
    template <typename Type>  
    class MyMathFuncs   
    {
    public:
        static __declspec(dllexport) Type Add(Type a, Type b);

        static __declspec(dllexport) Type Subtract(Type a, Type b);

        static __declspec(dllexport) Type Multiply(Type a, Type b);

        static __declspec(dllexport) Type Divide(Type a, Type b);

    };


}

Definitions of these functions:

#include "MathFuncsDll.h"

#include <stdexcept>

using namespace std;

namespace MathFuncs
{
    template <typename Type>
    Type MyMathFuncs<Type>::Add(Type a,Type b)
    { return a+b; }

    template <typename Type>
    Type MyMathFuncs<Type>::Subtract(Type a,Type b)
    { return a-b; }

    template <typename Type>
    Type MyMathFuncs<Type>::Multiply(Type a,Type b)
    { return a*b; }

    template <typename Type>
    Type MyMathFuncs<Type>::Divide(Type a,Type b)
    { 
        if(b == 0) throw new invalid_argument("Denominator cannot be zero!");
        return a/b; 
    }
}

Running this program fails:

1>main.obj : error LNK2001: unresolved external symbol “public: static int __cdecl MathFuncs::MyMathFuncs::Add(int,int)” (?Add@?$MyMathFuncs@H@MathFuncs@@SAHHH@Z)
1>C:\Users\Tomek\Documents\Visual Studio 2010\Projects\clean_rough_draft\Release\clean_rough_draft.exe : fatal error LNK1120: 1 unresolved externals

Could you point out my mistake?

  • 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-10T22:29:08+00:00Added an answer on June 10, 2026 at 10:29 pm

    The problem has nothing to do with delayed loading of the DLL or not. I can see two problems here:

    1. You are exporting templated functions. This wouldn’t work that way because template exporting is not supported in Visual C++ compiler and however has already been dropped from the standard. For this to work you have two possible solutions:

      • Move the implementations of the methods in the .h file, thus no longer needing a DLL at all as all the code is in a header file;
      • Instantiate the templates with the types that you will use in your client application. This is done be putting instantiation code with exact types in your cpp file, doing some extern template declarations in the header, etc. You can look that up in Google for more information, just search for ‘extern template DLL’ or something similar.
    2. You only export the methods when creating the DLL, but never import them (or at least that’s what I see from the code). You use __declspec(dllexport) in front of each method, which tells the compiler to put that methods in the DLL. When you want to use these methods from a client application, you have to import them from the DLL. This is done by placing __declspec(dllimport) in front of each method. Since you can not put both prefixes on the methods you either have to create two almost the same header files that just differ on that method prefix thing or use some macro substitution based on whether this is a DLL building code or a client application. Once again, you can look that up in Google to see how its done.

    I hope that helps.

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

Sidebar

Related Questions

For the sake of simplicity, I will drastically reduce the complexity of my project
I really love the simplicity of xajax calls from PHP, however xajax project seems
For simplicity, I'll refer to both the distributor's ControlInputQueue and it's StorageQueue as the
I like the apparent simplicity of JdbcTemplate but am a little confused as to
Please forgive the simplicity of this question. The answer will be obvious to many
Sorry for the simplicity of the question. New to Matlab and despite its thorough
Edit For simplicity: I just want to make the most basic possible cursor that
Consider the following code (for simplicity, I did not follow any C# coding rules).
Suppose I have the following (shortened for simplicity): jQuery(#grid).jqGrid({ ... ondblClickRow: function() { //
This requirement is just for simplicity for developers and beautiful code. I'm building a

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.