Qt World Summit: Submit your Presentation

Issue compiling Qt project with Mingw make in Windows command line - SetupApi.lib

  • Hey everybody, I'm creating a build machine for my Qt project such that everyday my machine checks out a fresh copy of the project repository and cleans, makes, and builds it in the command line using Mingw492 and Qmake. The build is currently failing, and I believe that the issue has to do with the path to the Windows SetupApi.lib. The problem is given below:

    g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\Project.exe object_script.Project.Release  -lmingw32 -LC:/Qt/5.5/mingw492_32/lib -lqtmain -lshell32 -lQt5WebKitWidgets -lQt5Widgets -lQt5WebKit -lQt5Gui -lQt5Network -lQt5Core release\Project_Logo_res.o 
    /release\devicehandler.o:devicehandler.cpp:(.text+0x3b2): undefined reference to `_imp__SetupDiEnumDeviceInterfaces@20'
    ./release\devicehandler.o:devicehandler.cpp:(.text+0x3de): undefined reference to `_imp__SetupDiEnumDeviceInfo@12'
    ./release\devicehandler.o:devicehandler.cpp:(.text+0x3ea): undefined reference to `_imp__SetupDiGetDeviceInterfaceDetailW@24'
    ./release\devicehandler.o:devicehandler.cpp:(.text+0x2244): undefined reference to `_imp__SetupDiGetClassDevsW@16'
    C:/Qt/Tools/mingw492_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld.exe: ./release\devicehandler.o: bad reloc
     address 0x11 in section `.text$_ZN17HIDDeviceTotalWIND1Ev[__ZN17HIDDeviceTotalWIND1Ev]'
    collect2.exe: error: ld returned 1 exit status
    Makefile.Release:1657: recipe for target 'release\Project.exe' failed
    mingw32-make: *** [release\Project.exe] Error 1

    Currently, I call the SetupApi.lib in my project file, via a path variable in my pro.user file. So I am required to copy a pro.user file from a local working build (which is identical), into the freshly checked out repository (which does not have the path specified by default as this path is different on ever team members machine).

    .pro file:

    win32 {
        RC_FILE = Project_Logo.rc
        LIBS += "$$(SETUPAPILIB)"

    Copied .pro.user file:

    pro user file image

    My PowerShell build sequence is...

    Set-Location "$ProjectBuildPath"
    & "$MingwPath\mingw32-make.exe" clean
    & "$QmakePath\qmake.exe" "$ProjectPath\Project.pro" -spec win32-g++ "CONFIG+=release"
    Set-Location "$ProjectBuildPath"
    & "$MingwPath\mingw32-make.exe" -f Makefile.Release

    I can build this exact same project with the copied pro.user file in QtCreator with no issue, but the command line fails after getting about nine minutes into the build. Can anyone help me out with this one?

  • It sounds like you have a dirty build. That is usually when you get bad reloc errors.

    Make sure you are building in a completely clean directory (shadow style building), or make sure all your objects and libs and such have been removed first.

    I would go as far as getting a clean check out from source control in a separate directory that has never had any builds done, and try in there. This error is almost always dirty builds. In fact I've never encountered it where a clean rebuild didn't fix it.

Log in to reply