Hi, the command is as follows:
gcc -o main.dll dllmain.o -L/c/Users/Androide/Desktop/colo/pupa/dllmain/ -lSDL -lSDLmain -lmingw32
I get the error when compiling my project, the error is as follows:
> $ gcc -o main.dll dllmain.o
> -L/c/Users/Androide/Desktop/colo/pupa/dllmain/ -lSDL -lSDLmain -lmingw32 C:/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/6.3.0/../../../../i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o):
> In function `main':
> C:/repo/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18:
> undefined reference to `WinMain@16' collect2.exe: error: ld returned 1
> exit status
And the code of my dll that I am compiling:
#include "stdafx.h"
#include <SDL/SDL.h>
#include <windows.h>
extern "C" __declspec (dllexport) void __cdecl HelloWorld()
{
//Show a message box with the text "Hello World"
MessageBox(NULL, TEXT("Hello World"), TEXT("In a DLL"), MB_OK);
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
//Different behaviors depending on the reason why DllMain is called
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
HelloWorld();
break;
case DLL_PROCESS_DETACH:
HelloWorld();
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
It seems that linking to -LSDL could solve it but it didn't work for me.
To generate a dll with minGW you must use a statement similar to the following:
Look at the part that I highlight. if you don't do it like this, a DLL will not be generated but an executable (I remind you that the C++ compilation does not understand extensions, so telling gcc that the output is
fichero.dll
does not make it understand that it should generate a DLL.