8

I try to compile a very simple dynamic library project as .dll file. The name of the project is "Library". I'm using Visual Studio 2015 and the project properties are these:

Debug Properties

Release Properties

In the project there are two files only: ClassA.h and ClassA.cpp.

The code in ClassA.h is:

#ifndef CLASSA_H
#define CLASSA_H

using namespace std;

#ifdef LIBRARY_EXPORTS
#define CLASSA_API __declspec(dllexport) 
#else
#define CLASSA_API __declspec(dllimport) 
#endif

class ClassA
{
public:
    static CLASSA_API void func();
};


#endif

The code in ClassA.cpp is:

#include "ClassA.h"
#include <iostream>


void ClassA::func()
{
    cout << "SUCCESS!" << endl;
}

When I try to compile this project I receive this error:

Severity Code Description Project File Line Error LNK1561 entry point must be defined Library C:\Users\UX303\Documents\Visual Studio 2015\DLLTest\Library\LINK 1

Radioga
  • 416
  • 1
  • 5
  • 16
  • 1
    did you read https://msdn.microsoft.com/en-us/library/ky737ya4.aspx?f=255&MSPPError=-2147217396 ? – Luchian Grigore May 30 '16 at 15:27
  • Yes, but I have not had a good result. – Radioga May 30 '16 at 15:55
  • This is quite hard to get wrong, the entrypoint is built into the C runtime library and not linking it produces a different error. Only one thing I can think of, the Project > Properties > Linker > Advanced > "Entry Point" setting is used. That can be a problem when you try to build the x64 flavor of the DLL, as shown in the screenshot, the name decoration applied to the function is different. No leading underscore, no @ postfix. Do beware that is quite risky to do this, the CRT won't be initialized. – Hans Passant Nov 25 '18 at 13:52

2 Answers2

16

It is likely that your configuration is not right.

Be sure to double check your "Active Configuration" (Debug / Release), to see if you are really building a DLL.

I have just made such a mistake, and came across this question.

sanbrother
  • 244
  • 3
  • 5
  • 2
    When you switch from debug to release the profile gets reset to an EXE, when it should be a DLL. So check the config. Also if you are deploying to another machine you must set it to Release. And - I'm not sure if this is 100% required, but there is a package "Microsoft C++ Redistributable" that I installed on the client machine, once I did these two things the error went away. – Rob Nov 21 '20 at 14:53
3

In 64 bit machine I was getting same error when 'Solution Platforms' set to 'x86'. The error goes away when I set the 'Solution Platforms' to 'x64'.

Pabitra Dash
  • 1,461
  • 2
  • 21
  • 28
  • unbelievable, I spent an hour before i read this and realized my platform got set to x86 for some random reason – iedoc Dec 18 '18 at 15:47