I am having hard time figuring out how to link WinInet when compiling from bash shell in windows (msys)
'Makefile
'
main:
g -s -static -static-libgcc -static-libstdc -lwininet main.cpp -o main
'main.cpp
'
#include <Windows.h>
#include <wininet.h>
#define MAX 4096
#pragma comment (lib, "Wininet.lib")
void Request()
{
HINTERNET hSession = InternetOpen("", INTERNET_OPEN_TYPE_PRECONFIG, NULL,NULL,0);
}
int main()
{
Request();
return 0;
}
The error I got
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\tmp\cc1m5iEc.o:main.cpp:(.text 0xfa6): undefined reference to `__imp_InternetOpenA'
Things I tried :
- looked the path where
WinInet.lib
was and tried to use it with-L
like sog -L"path\\to\\WinInet.lib" main.cpp
- changed
#pragma comment (lib, "Wininet.lib")
to#pragma comment (lib, "WinInet.lib")
- Tried using
-m64
- Tried th
-L
method withoutWinInet.lib
How to properly link wininet from bash shell in msys
MSYS download link
CodePudding user response:
The problem is in your make file, you should move -lwininet
after main.cpp
g -s main.cpp -static -static-libgcc -static-libstdc -lwininet -Os -o main