0
votes

With mingw-w64 version 4.9.1, installed with the MSYS2 installer, I'm building a DLL and linking it to ws2_32.dll using the -lws2_32 option. But mingw-w64 can't find ws2_32.dll under that name:

*** Warning: linker path does not have real file for library -lws2_32.

If I go into C:\Windows\system32 and copy ws2_32.dll to libws2_32.dll, then mingw-w64 can find it. This seems like a bad hack, however. I tried -l:ws2_32 since I read that the ":" has special meaning, but that made no difference.

How can I tell mingw-w64 to link to a Windows DLL whose name does not begin with lib?

2
It's been a while, so this might not work, but try linking with -lws2_32.dll. - slugonamission
In addition, also try specifying the name of the .dll on the command line without -l. - slugonamission
You should be able to use -l:ws2_32.dll. With the colon, you must specify the complete file name, including extension, but the linker still searches the library path for it. - John Bollinger

2 Answers

1
votes

Have you tried fore-going the -l option?

Just

gcc -LC:\Windows\system32 herpmytargetcodederp.c ws2_32.dll

Items fed into gcc are either object files or libraries. The -l option is just a common way of linking in commonly used things a little easier. The old farts were terse. -lm instead of typing out -L/path/to/lib libmath.o

Include the path for the linker to find it with -L and call it by name.

1
votes

you do not link to the DLL itself, but to the library that defines the dll exports (libws2_32.a), check in your MingW (\lib) directory if libws2_32.a exists.