0

I use Cygwin to build source code to DLL used by windows app.

When I use GCC core / GCC g++, the app crash if it calls function (which includes printf or malloc) in DLL.

When I use Mingw64-x86_64-gcc-core / Mingw64-x86_64-gcc-g++ it reports error like sys/socket.h:No such file or directory.

Can anyone explain how to do it? Thanks.

kit
  • 1,166
  • 5
  • 16
  • 23
Wang Hai
  • 791
  • 1
  • 6
  • 7

1 Answers1

1

The first problem is due to the tentative to build a stand alone DLL (not depending on cygwin1.dll) using cygwin only specific tools. You have collision between multiple malloc and other C library call present in cygwin1.dll.

The second is due to the fact that sys/socket.h does not exist on Windows see for possible solution: Using sys/socket.h functions on windows

So you need to define what is your target : Cygwin/Posix or Windows and choose programming style and tools accordingly, you can not mix.

matzeri
  • 8,062
  • 2
  • 15
  • 16
  • Hi, for the first problem, I build a DLL (depends on cygwin1.dll), and create a windows console app with Visual Studio to load the DLL, and call a function in it. If the function contains malloc, the app crashes. So Why there are multiple malloc? Thanks. – Wang Hai Nov 17 '18 at 06:08
  • Visual Studio program uses the Windows C malloc, the Cygwin DLL uses the one in cygwin1.dll. You need to use the same tools for both app and dll – matzeri Nov 17 '18 at 06:53