Search code examples
c++linkercross-compilingmingw-w64

Cross Compiling from Linux-Windows, stdio has undefined references (to __imp___acrt_iob_func)


As the title says, I've been trying to cross compile a fairly large project with quite a few dependencies (both static and dynamic libraries). I've cross compiled every dependency successfully using MinGW-w64, set the include & library search paths to their MinGW counterparts (/usr/x86_64-w64-mingw32/lib & include), and yet on the linking step MinGW throws out an error for each call of printf (with stdio.h included, of course). The errors are as follows:

/usr/bin/x86_64-w64-mingw32-ld: ./obj/XXXX.o:/usr/share/mingw-w64/include/stdio.h:352: undefined reference to `__imp___acrt_iob_func'

(Where "XXXX" is a file name from my project)

This error is repeated the exact same (with the exception of the object file name). The command for linking looks like this:

/usr/bin/x86_64-w64-mingw32-g++ -o bin/ReleaseWin/Project @[file with object file names] -L. -L/usr/x86_64-w64-mingw32/lib/ [linking some dependencies (boost, openGL, SDL2, etc.)...] -m64 -flto

I've searched for a solution (or even someone with the same problem) to no avail. I've never been well-versed in linking any more than regular libraries, so if you need more information just ask.

Thanks in advance :)

Extra info:

  • This project has been cross compiled (from Linux to Windows) successfully before, and I haven't added/removed any dependencies since.
  • My MinGW-w64 version is 7.0.0

Solution

  • So, I apt-get purge'd mingw-w64 and mingw-w64-common, reinstalled just mingw-w64, and now it's working...

    This might have something to do with the fact that I followed the issue that Richard Critten commented with (thanks!), which led me to try downloading and manually copy/pasting headers and CRT (mingw-w64-x86_64-headers-git-... & mingw-w64-x86_64-crt-git) from the MSYS2 repository. That didn't work right away (probably because I screwed up and used the 5.0.0 versions instead of my version), but it seems to have done something.

    Therefore, for those who stumble upon this issue,

    1. Try a re-install of MinGW (of course),
    2. Try manually adding the CRT and headers from the link I supplied, and if that still doesn't work,
    3. Try re-installing MinGW again. I'm not super familiar with apt, so I don't know if adding the CRT and headers actually changed how it installed MinGW, but it's worth a shot I guess.

    Update: I had this exact same problem on another system. Simply reinstalling MinGW fixed it, so it seems like maybe there was some sort of issue with the files? It's possible that updating from an earlier version messed with things. Moral of the story: even if you think your files are good, a reinstall can't hurt.