I need to use cygwin compiled dll from visual studio C++ or Code:blocks MinGW.
I tried use this simple example
#include <stdio.h>
int MyFunc()
{
printf("Printed from cygwin dll");
return 0;
}
And this makefile
obj = mydll.o
ALLLIBS = \
mydll.a \
mydll.dll
all: $(ALLLIBS)
mydll.a: $(obj)
$(LINK.a)
mydll.dll: $(obj)
$(cygTest.dll)
cygTest.dll = gcc -shared -o cygTest.dll \
-Wl,--out-implib \
-Wl,--export-all-symbols \
-Wl,--enable-auto-import \
-Wl,--whole-archive $(obj) \
-Wl,--no-whole-archive
mydll.a = ar $(ARFLAGS) $@ $%
I am trying to call the final dll here.
#include <windows.h>
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
typedef int(*FnP_MyFunc)();
typedef void(*FnP_CYGWIN_DLL_INIT)();
int main()
{
FnP_MyFunc fnMyFunc;
HMODULE hLib, hGetCygwinIDDLL = LoadLibrary(TEXT("C:\\cygwin64\\bin\\cygwin1.dll"));
if (hGetCygwinIDDLL)
{
FnP_CYGWIN_DLL_INIT init = (FnP_CYGWIN_DLL_INIT)GetProcAddress(hGetCygwinIDDLL, "cygwin_dll_init");
init();
std::cout << "init complete " << endl;
}
int a;
hLib = LoadLibrary(TEXT("C:\\cygwin64\\home\\azatyan\\TestDynamicLink\\cygTest.dll"));
if (hLib)
{
std::cout << "From wrapper dll " << std::endl;
fnMyFunc = (FnP_MyFunc)GetProcAddress(hLib, "MyFunc");
a = fnMyFunc();
cout << a;
}
FreeLibrary(hGetCygwinIDDLL);
FreeLibrary(hLib);
return 0;
}
And it just hangs when it reaches to my MyFunc function. Or exits with code 1536.. Can anybody help me, what am I doing wrong?
UPDATE: I have tried the same without printf()
function, worked ok, returned expected value, this means that the problem is in dependency libraries, but still I don't know haw I can add all dependency libraries..