Search code examples
mingw-w64

Linking fails for GetSaveFileName when cross compiling with MinGW


I'm trying to compile a modified version of UniLogger on Ubuntu 18.04 using mingw. I'm getting the following link error:

undefined reference to '_imp__GetSaveFileNameW@4'

I found this post on the MinGW mailing list saying one needs to explicitly link to comdlg32 so I tried that also:

i686-w64-mingw32-g++ -municode -o unilogger.exe -lcomdlg32 Source.cpp

But still got the same error, as did the person asking in the post. He and I both verified the presence of the function in the lib file:

nm /usr/i686-w64-mingw32/lib/libcomdlg32.a

libcomdlg32s00012.o:
00000000 b .bss
00000000 d .data
00000000 T _GetSaveFileNameW@4
         U __head_lib32_libcomdlg32_a
00000000 i .idata$4
00000000 i .idata$5
00000000 i .idata$6
00000000 i .idata$7
00000000 I __imp__GetSaveFileNameW@4
00000000 t .text

libcomdlg32s00011.o:
00000000 b .bss
00000000 d .data
00000000 T _GetSaveFileNameA@4
         U __head_lib32_libcomdlg32_a
00000000 i .idata$4
00000000 i .idata$5
00000000 i .idata$6
00000000 i .idata$7
00000000 I __imp__GetSaveFileNameA@4
00000000 t .text

I'm at a bit of a loss at this point.


Solution

  • OK, figured out what the problem was - order of arguements on the command line:

    i686-w64-mingw32-g++ -lcomdlg32 -municode -o unilogger.exe

    gives the link error, however

    i686-w64-mingw32-g++ -municode -o unilogger.exe -lcomdlg32

    Compiles just fine. Actually think I've run into this problem before with gcc now that I think of it...