'Porting application (made on top of miniupnpc) from linux to windows, trying to build using mingw, linking failure on windows
I am a newbie with mingw and trying to port an application I have built on top of miniupnpc. The application works fine on linux but unable to compile it on windows because of a linking error.
I am using mingw64 (installed via msys2) and installed following libraries:
pacman -S base-devel mingw-w64-x86_64-toolchain
pacman -S mingw-w64-x86_64-miniupnpc
Question: I am not sure what I am missing that is causing this linking error. Any pointers how I can resolve this issue and get my application to build successfully??
Error:
gcc -o ../bin/pjmedia-test-x86_64-w64-mingw32 \
output/pjmedia-test-x86_64-w64-mingw32/codec_vectors.o output/pjmedia-test-x86_64-w64-mingw32/jbuf_test.o output/pjmedia-test-x86_64-w64-mingw32/main.o output/pjmedia-test-x86_64-w64-mingw32/mips_test.o output/pjmedia-test-x86_64-w64-mingw32/vid_codec_test.o output/pjmedia-test-x86_64-w64-mingw32/vid_dev_test.o output/pjmedia-test-x86_64-w64-mingw32/vid_port_test.o output/pjmedia-test-x86_64-w64-mingw32/rtp_test.o output/pjmedia-test-x86_64-w64-mingw32/test.o output/pjmedia-test-x86_64-w64-mingw32/sdp_neg_test.o -lpjmedia-codec-x86_64-w64-mingw32 -lpjmedia-videodev-x86_64-w64-mingw32 -lpjmedia-audiodev-x86_64-w64-mingw32 -lpjmedia-x86_64-w64-mingw32 -lpjnath-x86_64-w64-mingw32 -lpjlib-util-x86_64-w64-mingw32 -lpj-x86_64-w64-mingw32 -lsrtp-x86_64-w64-mingw32 -lresample-x86_64-w64-mingw32 -lgsmcodec-x86_64-w64-mingw32 -lspeex-x86_64-w64-mingw32 -lilbccodec-x86_64-w64-mingw32 -lg7221codec-x86_64-w64-mingw32 -lyuv-x86_64-w64-mingw32 -lminiupnpc-x86_64-w64-mingw32 -lwebrtc-x86_64-w64-mingw32 -lbaseclasses-x86_64-w64-mingw32 -lssl -lcrypto -lopenh264 -lstdc++ -lm -lwinmm -lole32 -lws2_32 -lwsock32 -lpthread -lstdc++ -lquartz -lole32 -loleaut32 -lrpcrt4 -lwinmm -luuid -lmingwex -lstrmiids -LC:/msys64/mingw64/lib -lmingw32 -lSDL2main -lSDL2 -LC:/workspace/pjsip/pjlib/lib -LC:/workspace/pjsip/pjlib-util/lib -LC:/workspace/pjsip/pjnath/lib -LC:/workspace/pjsip/pjmedia/lib -LC:/workspace/pjsip/pjsip/lib -LC:/workspace/pjsip/third_party/lib -LC:/msys64/mingw64/lib -lmingw32 -lSDL2main -lSDL2 -lstdc++ -lquartz -lole32 -loleaut32 -lrpcrt4 -lwinmm -luuid -lmingwex -lstrmiids -lopenh264 -lstdc++ -LC:/msys64/mingw64/lib -lmingw32 -lSDL2main -lSDL2 -lstdc++ -lquartz -lole32 -loleaut32 -lrpcrt4 -lwinmm -luuid -lmingwex -lstrmiids -lopenh264 -lstdc++ -LC:/msys64/mingw64/lib -lmingw32 -lSDL2main -lSDL2 -lstdc++ -lquartz -lole32 -loleaut32 -lrpcrt4 -lwinmm -luuid -lmingwex -lstrmiids -lopenh264 -lstdc++
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text+0x86): undefined reference to `__imp_UPNP_GetConnectionTypeInfo'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text+0xc3): undefined reference to `__imp_UPNP_GetStatusInfo'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text+0xfe): undefined reference to `__imp_UPNP_GetLinkLayerMaxBitRates'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text+0x122): undefined reference to `__imp_UPNP_GetExternalIPAddress'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text+0x4be): undefined reference to `__imp_UPNP_GetExternalIPAddress'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text+0x531): undefined reference to `__imp_UPNP_AddAnyPortMapping'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text+0x58e): undefined reference to `__imp_UPNP_GetSpecificPortMappingEntry'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text+0x64a): undefined reference to `__imp_UPNP_AddPortMapping'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text+0x663): undefined reference to `__imp_strupnperror'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text+0x698): undefined reference to `__imp_strupnperror'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text+0x6f4): undefined reference to `__imp_strupnperror'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x53c): undefined reference to `__imp_UPNP_GetIGDFromUrl'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x57c): undefined reference to `__imp_UPNP_GetValidIGD'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x60b): undefined reference to `__imp_FreeUPNPUrls'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x616): undefined reference to `__imp_freeUPNPDevlist'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x8d6): undefined reference to `__imp_upnpDiscover'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0xa37): undefined reference to `__imp_UPNP_GetTotalBytesSent'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0xa4b): undefined reference to `__imp_UPNP_GetTotalBytesReceived'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0xa5f): undefined reference to `__imp_UPNP_GetTotalPacketsSent'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0xa73): undefined reference to `__imp_UPNP_GetTotalPacketsReceived'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0xc0f): undefined reference to `__imp_UPNP_DeletePortMappingRange'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0xc76): undefined reference to `__imp_UPNP_GetListOfPortMappings'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0xd1a): undefined reference to `__imp_FreePortListing'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0xdc1): undefined reference to `__imp_FreePortListing'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0xdce): undefined reference to `__imp_strupnperror'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0xdef): undefined reference to `__imp_UPNP_GetPinholePackets'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0xdf6): undefined reference to `__imp_strupnperror'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0xf0a): undefined reference to `__imp_UPNP_GetOutboundPinholeTimeout'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0xf1c): undefined reference to `__imp_strupnperror'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0xf6a): undefined reference to `__imp_UPNP_DeletePinhole'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0xfce): undefined reference to `__imp_UPNP_CheckPinholeWorking'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x104b): undefined reference to `__imp_strupnperror'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x117e): undefined reference to `__imp_UPNP_AddPinhole'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x1190): undefined reference to `__imp_strupnperror'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x120c): undefined reference to `__imp_UPNP_DeletePortMapping'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x130a): undefined reference to `__imp_UPNP_CheckPinholeWorking'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x136a): undefined reference to `__imp_UPNP_UpdatePinhole'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x138e): undefined reference to `__imp_strupnperror'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x13ec): undefined reference to `__imp_UPNP_GetFirewallStatus'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x144d): undefined reference to `__imp_UPNP_GetTotalBytesSent'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x1461): undefined reference to `__imp_UPNP_GetTotalBytesReceived'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x1475): undefined reference to `__imp_UPNP_GetTotalPacketsSent'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x1489): undefined reference to `__imp_UPNP_GetTotalPacketsReceived'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x1670): undefined reference to `__imp_UPNP_GetGenericPortMappingEntry'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x1680): undefined reference to `__imp_strupnperror'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x177a): undefined reference to `__imp_strupnperror'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/workspace/pjsip/third_party/lib/libminiupnpc-x86_64-w64-mingw32.a(upnpc.o):upnpc.c:(.text.startup+0x179f): undefined reference to `__imp_strupnperror'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [C:/workspace/pjsip/build/rules.mak:125: ../bin/pjmedia-test-x86_64-w64-mingw32] Error 1
make[2]: Leaving directory '/c/workspace/pjsip/pjmedia/build'
make[1]: *** [Makefile:245: pjmedia-test-x86_64-w64-mingw32] Error 2
make[1]: Leaving directory '/c/workspace/pjsip/pjmedia/build'
make: *** [Makefile:14: all] Error 1
Solution 1:[1]
You link with -lminiupnpc-x86_64-w64-mingw32.
Do you have libminiupnpc-x86_64-w64-mingw32.dll.a, or just libminiupnpc-x86_64-w64-mingw32.a?
Because the error indicates it's trying to link with dllimported symbols...
If you want to use the static library you can get around that by adding compiler flag -DMINIUPNP_STATICLIB to tell the miniupnpc header files to use the static symbols.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Brecht Sanders |
