#305 mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMa

closed-invalid
nobody
crt (85)
5
2014-03-30
2012-07-01
Yuchen Deng
No

After build Qt5 use mingw-w64 on Ubuntu 12.04, I can't build qbs (Qt Build Suit) use MinGW-w64.

linking ui.exe
/usr/bin/x86_64-w64-mingw32-g++ -m64 -O2 -Wall -W /home/loaden/qpSOFT/Projects/Qbs/tests/manual/uic/build/m64-mingw64-release/.obj/ui/bla.o -o /home/loaden/qpSOFT/Projects/Qbs/tests/manual/uic/build/m64-mingw64-release/ui.exe -L/home/loaden/qpSOFT/Projects/BuildQt5-m64/qtbase/lib -lqtmain -lQtCore5 -lQtGui5
/usr/lib/gcc/x86_64-w64-mingw32/4.6/../../../../x86_64-w64-mingw32/lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): In function `main':
/build/buildd/mingw-w64-2.0.3/build/x86_64-w64-mingw32/all/mingw-w64-crt/../../../../mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'
collect2: ld returned 1 exit status

Discussion

  • Jonathan Yong

    Jonathan Yong - 2012-07-01

    This is a symptom from missing main() or WinMain() entry points. The error stems from the user code.

     
  • Jonathan Yong

    Jonathan Yong - 2012-07-01
    • status: open --> closed-invalid
     
  • Yuchen Deng

    Yuchen Deng - 2012-07-01

    No! same code can build successful use linux gcc or msvc. the WinMain entry function compiled into libqtmain.a.

     
  • Yuchen Deng

    Yuchen Deng - 2012-07-01
    • status: closed-invalid --> open-invalid
     
  • Jonathan Yong

    Jonathan Yong - 2012-07-01

    Are you sure? If that is the case, you will not get this error, please double check your code, libqtmain or whatnot.

    Please add -v to your link command and post the output as well.

     
  • Yuchen Deng

    Yuchen Deng - 2012-07-01

    Here is the verbose log:

    loaden@qpsoft:~/qpSOFT/Projects/Qbs/tests/manual/uic$ /usr/bin/x86_64-w64-mingw32-g++ -v -m64 -O2 -Wall -W /home/loaden/qpSOFT/Projects/Qbs/tests/manual/uic/build/m64-mingw64-release/.obj/ui/bla.o -o /home/loaden/qpSOFT/Projects/Qbs/tests/manual/uic/build/m64-mingw64-release/ui.exe -L/home/loaden/qpSOFT/Projects/BuildQt5-m64/qtbase/lib -lqtmain -lQtCore5 -lQtGui5
    Using built-in specs.
    COLLECT_GCC=/usr/bin/x86_64-w64-mingw32-g++
    COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-w64-mingw32/4.6/lto-wrapper
    Target: x86_64-w64-mingw32
    Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-threads=win32 --enable-fully-dynamic-string --enable-sjlj-exceptions --enable-languages=c,c++,fortran,objc,obj-c++,ada --enable-lto --with-plugin-ld --target=x86_64-w64-mingw32 --with-gxx-include-dir=/usr/include/c++/4.6 --with-as=/usr/bin/x86_64-w64-mingw32-as --with-ld=/usr/bin/x86_64-w64-mingw32-ld
    Thread model: win32
    gcc version 4.6.3 (GCC)
    COMPILER_PATH=/usr/lib/gcc/x86_64-w64-mingw32/4.6/:/usr/lib/gcc/x86_64-w64-mingw32/4.6/:/usr/lib/gcc/x86_64-w64-mingw32/:/usr/lib/gcc/x86_64-w64-mingw32/4.6/:/usr/lib/gcc/x86_64-w64-mingw32/
    LIBRARY_PATH=/usr/lib/gcc/x86_64-w64-mingw32/4.6/:/usr/lib/gcc/x86_64-w64-mingw32/4.6/../../../../x86_64-w64-mingw32/lib/
    COLLECT_GCC_OPTIONS='-v' '-m64' '-O2' '-Wall' '-Wextra' '-o' '/home/loaden/qpSOFT/Projects/Qbs/tests/manual/uic/build/m64-mingw64-release/ui.exe' '-L/home/loaden/qpSOFT/Projects/BuildQt5-m64/qtbase/lib' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
    /usr/lib/gcc/x86_64-w64-mingw32/4.6/collect2 -m i386pep -Bdynamic -o /home/loaden/qpSOFT/Projects/Qbs/tests/manual/uic/build/m64-mingw64-release/ui.exe /usr/lib/gcc/x86_64-w64-mingw32/4.6/../../../../x86_64-w64-mingw32/lib/crt2.o /usr/lib/gcc/x86_64-w64-mingw32/4.6/../../../../x86_64-w64-mingw32/lib/crtbegin.o -L/home/loaden/qpSOFT/Projects/BuildQt5-m64/qtbase/lib -L/usr/lib/gcc/x86_64-w64-mingw32/4.6 -L/usr/lib/gcc/x86_64-w64-mingw32/4.6/../../../../x86_64-w64-mingw32/lib /home/loaden/qpSOFT/Projects/Qbs/tests/manual/uic/build/m64-mingw64-release/.obj/ui/bla.o -lqtmain -lQtCore5 -lQtGui5 -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt /usr/lib/gcc/x86_64-w64-mingw32/4.6/../../../../x86_64-w64-mingw32/lib/crtend.o
    /usr/lib/gcc/x86_64-w64-mingw32/4.6/../../../../x86_64-w64-mingw32/lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): In function `main':
    /build/buildd/mingw-w64-2.0.3/build/x86_64-w64-mingw32/all/mingw-w64-crt/../../../../mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'
    collect2: ld returned 1 exit status

     
  • Yuchen Deng

    Yuchen Deng - 2012-07-03

    Any comments about the verbose log?

     
  • Yuchen Deng

    Yuchen Deng - 2012-07-03
    • status: open-invalid --> open
     
  • Jonathan Yong

    Jonathan Yong - 2012-07-04

    Not really, can you post the nm listing of libqtmain.a?

     
  • Yuchen Deng

    Yuchen Deng - 2012-07-04

    D:\qpSOFT\Projects\BuildQt5-m64\qtbase\lib>D:\qpSOFT\MinGW\MinGW64\bin\nm.exe libqtmain.a
    0000000000000000 b .bss
    0000000000000000 d .data
    0000000000000000 p .pdata
    0000000000000000 p .pdata$_ZN7QVectorIPcE11reallocDataEii6QFlagsIN10QArrayData16AllocationOptionEE
    0000000000000000 t .text
    0000000000000000 t .text$_ZN7QVectorIPcE11reallocDataEii6QFlagsIN10QArrayData16AllocationOptionEE
    0000000000000000 r .xdata
    0000000000000000 r .xdata$_ZN7QVectorIPcE11reallocDataEii6QFlagsIN10QArrayData16AllocationOptionEE
    U __imp__ZN10QArrayData10deallocateEPS_yy
    U __imp__ZN10QArrayData11shared_nullE
    U __imp__ZN10QArrayData8allocateEyyy6QFlagsINS_16AllocationOptionEE
    U __imp__ZN10QByteArray11reallocDataEj6QFlagsIN10QArrayData16AllocationOptionEE
    U __imp__ZN7QString9fromUtf16EPKti
    U __imp__ZNK7QString11toLocal8BitEv
    U __imp_GetCommandLineW
    U _Z5qMainiPPc
    U _Z8qWinMainP11HINSTANCE__S0_PciRiR7QVectorIS1_E
    0000000000000000 T _ZN7QVectorIPcE11reallocDataEii6QFlagsIN10QArrayData16AllocationOptionEE
    0000000000000000 t _ZN7QVectorIPcE16defaultConstructEPS0_S2_.isra.3
    U memcpy
    U memset
    0000000000000020 T WinMain

     
  • Yuchen Deng

    Yuchen Deng - 2012-07-04

    Same issue under Windows 7 64bit, use x86_64-w64-mingw32-gcc-4.6.3-release-win64_rubenvb.7z

     
  • Yuchen Deng

    Yuchen Deng - 2012-07-04

    On Linux (Ubuntu 12.04)
    loaden@qpsoft:~/qpSOFT/Projects/BuildQt5-m64/qtbase/lib$ x86_64-w64-mingw32-nm ./libqtmain.a

    qtmain_win.o:
    0000000000000000 b .bss
    0000000000000000 d .data
    0000000000000000 p .pdata
    0000000000000000 p .pdata$_ZN7QVectorIPcE11reallocDataEii6QFlagsIN10QArrayData16AllocationOptionEE
    0000000000000000 t .text
    0000000000000000 t .text$_ZN7QVectorIPcE11reallocDataEii6QFlagsIN10QArrayData16AllocationOptionEE
    0000000000000000 r .xdata
    0000000000000000 r .xdata$_ZN7QVectorIPcE11reallocDataEii6QFlagsIN10QArrayData16AllocationOptionEE
    0000000000000020 T WinMain
    U _Z5qMainiPPc
    U _Z8qWinMainP11HINSTANCE__S0_PciRiR7QVectorIS1_E
    0000000000000000 T _ZN7QVectorIPcE11reallocDataEii6QFlagsIN10QArrayData16AllocationOptionEE
    0000000000000000 t _ZN7QVectorIPcE16defaultConstructEPS0_S2_.isra.3
    U __imp_GetCommandLineW
    U __imp__ZN10QArrayData10deallocateEPS_yy
    U __imp__ZN10QArrayData11shared_nullE
    U __imp__ZN10QArrayData8allocateEyyy6QFlagsINS_16AllocationOptionEE
    U __imp__ZN10QByteArray11reallocDataEj6QFlagsIN10QArrayData16AllocationOptionEE
    U __imp__ZN7QString9fromUtf16EPKti
    U __imp__ZNK7QString11toLocal8BitEv
    U memcpy
    U memset

     
  • Jonathan Yong

    Jonathan Yong - 2012-07-04

    No idea, WinMain is there, try adding -mwindows.

     
  • Yuchen Deng

    Yuchen Deng - 2012-07-04

    -mwindows can't solve this issue.

    loaden@qpsoft:~/qpSOFT/Projects/Qbs/tests/manual/uic$ /usr/bin/x86_64-w64-mingw32-g++ -m64 -O2 -mwindows -Wall -W /home/loaden/qpSOFT/Projects/Qbs/tests/manual/uic/build/m64-mingw64-release/.obj/ui/bla.o -o /home/loaden/qpSOFT/Projects/Qbs/tests/manual/uic/build/m64-mingw64-release/ui.exe -L/home/loaden/qpSOFT/Projects/BuildQt5-m64/qtbase/lib -lqtmain -lQtCore5 -lQtGui5
    /usr/lib/gcc/x86_64-w64-mingw32/4.6/../../../../x86_64-w64-mingw32/lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): In function `main':
    /build/buildd/mingw-w64-2.0.3/build/x86_64-w64-mingw32/all/mingw-w64-crt/../../../../mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'

     
  • Jonathan Yong

    Jonathan Yong - 2012-07-04

    Sorry, no idea, I just tried on my end with a simple test case, I can't reproduce the issue.
    It would seem to be a linker issue though, nothing mingw-w64 specific.

    Btw, -mwindows is mandatory if you use WinMain.

     
  • Kai Tietz

    Kai Tietz - 2012-07-11

    Well, this is a Qt issue. Your app lacks a main and WinMain function. So an executable can't be linked.
    I admit that the linker-message about missing WinMain looks on the first hand a bit irretating, But we have to support ventures using for -mwindows GUI subsystem the function main as entry-point instead of proper WinMain one, so we have a forwarding main() to WinMain() imlementation in startup-code.

    So I close this bug as not a bug. please use instead mailing-list to get help about your issue.

     
  • Kai Tietz

    Kai Tietz - 2012-07-11
    • status: open --> closed-invalid
     
  • Jim Michaels

    Jim Michaels - 2014-03-30

    I have same issue with -m64 with a program. it uses no windows stuff. it's a console mode application. -console does nothing useful, -windows does nothing useful, stil get same error. this is with 4.9.0 x86_64 sjlj win32 experimental personal 2014 timestamped file.
    it actually executes. links just fine with -m32.
    used to be -m32 didn't work right, now it's -m64. but at least I get a running executable, but the ld error throws me off and I think there's a problem. static linking made no difference.

    f:/x86_64-4.9.0-snapshot-20140219-rev207854-win32-sjlj-rt_v4/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.0/../../../../x86_64-w64-mingw32/lib/../lib\libmingw3
    2.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x25): undefined reference to `WinMain'
    collect2.exe: error: ld returned 1 exit status

    as it is, I don't use -windows or -console.

    GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    Compiler executable checksum: 3d656286c2fbf9376b6c665d39c3c502
    COLLECT_GCC_OPTIONS='-m64' '-Wall' '-Wextra' '-v' '-save-temps' '-Ofast' '-static-libgcc' '-static' '-std=c++11' '-s' '-isystem' '/libpq/' '-isystem' '/libpq/se
    rver/libpq/' '-isystem' '/prj/fltk/fltk-2.0.x-alpha-r9042/' '-isystem' '/prj/fltk/fltk-2.0.x-alpha-r9042/lib/' '-isystem' '/prj/zlib-1.2.5/' '-isystem' '/prj/bo
    ost/boost64' '-o' '64\md5.exe' '-mtune=core2' '-march=nocona'
    f:/x86_64-4.9.0-snapshot-20140219-rev207854-win32-sjlj-rt_v4/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.0/../../../../x86_64-w64-mingw32/bin/as.exe -v --64

     

Log in to post a comment.