Thread: MinGW Linking GUI Program

  1. #16
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Sorry, that fails completely for me :
    g++ -c -Wall .cpp
    g++: .cpp: No such file or directory
    g++: no input files
    mingw32-make: *** [wurd.o] error 1
    (same with msys make).
    Quote Originally Posted by ming32-make
    GNU Make 3.80
    Quote Originally Posted by msys make
    GNU Make version 3.79.1
    Quote Originally Posted by g++
    g++.exe (GCC) 3.4.5 (mingw special)
    edit: spoke too soon- I've had to tweak your makefile to replicate the error you have described:
    Code:
    CC = g++
    LD = ld
    
    LIBS = "C:\Program Files\Microsoft Platform SDK\Lib\gdi32.Lib" "C:\Program Files\Microsoft Platform SDK\Lib\kernel32.lib"
    
    LDFLAGS  = --subsystem windows -e _WinMain@16 $(LIBS)
    CXXFLAGS = -c -Wall
    
    all: wurd
    
    wurd: wurd.o
    	$(LD) wurd.o -o wurd.exe $(LDFLAGS) 
    
    wurd.o: wurd.cpp
    	$(CC) $(CXXFLAGS) wurd.cpp
    edit2: MessageBox is in user32.dll so requires linking with user32.lib; not that it removes the linker error...
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  2. #17
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    I have made some progress. I realized that the symbol information in the VC libraries have a different mangling than mingw's. Here are some examples:

    Code:
    USER32.dll:     file format pei-i386
    
    SYMBOL TABLE:
    [  0](sec  0)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 .idata$4
    [  1](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 .idata$5
    [  2](sec  2)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 .idata$6
    [  3](sec  3)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 .text
    [  4](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __imp__wsprintfA
    [  5](sec  3)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 _wsprintfA
    [  6](sec  0)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __IMPORT_DESCRIPTOR_USER32
    
    
    
    USER32.dll:     file format pei-i386
    
    SYMBOL TABLE:
    [  0](sec  0)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 .idata$4
    [  1](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 .idata$5
    [  2](sec  2)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 .idata$6
    [  3](sec  3)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 .text
    [  4](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __imp__wsprintfW
    [  5](sec  3)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 _wsprintfW
    [  6](sec  0)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __IMPORT_DESCRIPTOR_USER32
    They do not have the appending number of argument bytes. With mingw's libs, I can do what I want when I say:

    Code:
    LIBPATH   = "C:/Development/Dev/lib"
    LIBS      = -l gdi32.a -l kernel32.a -l user32.a -l ws2_32.a
    Those forward slashes are needed. I am also trying to link to the standard library now, and am encountering some more errors. My makefile, with needed things to link

    Code:
    LIBPATH   = -L"C:/development/dev/lib" \
    			-L"C:/development/dev/lib/gcc/mingw32/3.4.2"
    
    LIBS      = -lgdi32 -lkernel32 -luser32 \
    			-lws2_32 -lstdc++ -lcrtdll \
    			-lmingw32 -lgcc
    
    LDFLAGS  = --subsystem windows $(LIBPATH) $(LIBS)
    
    test: test.o util.o
    	$(LD) C:\Development\Dev\lib\crt1.o test.o util.o -o test.exe $(LDFLAGS)
    I get many errors from like

    Code:
    ld C:\Development\Dev\lib\crt1.o test.o util.o -o test.exe --subsystem windows -L"C:/development/dev/lib" -L"C:/development/dev/lib/gcc/mingw32/3.4.2"
     -lgdi32 -lkernel32 -luser32 -lws2_32 -lstdc++ -lcrtdll -lmingw32 -lgcc
    C:/development/dev/lib/libstdc++.a(eh_globals.o)(.text+0x28):eh_globals.cc: undefined reference to `_imp__TlsAlloc@0'
    C:/development/dev/lib/libstdc++.a(eh_globals.o)(.text+0x58):eh_globals.cc: undefined reference to `_imp__GetLastError@0'
    C:/development/dev/lib/libstdc++.a(eh_globals.o)(.text+0xe4):eh_globals.cc: undefined reference to `_imp__GetLastError@0'
    C:/development/dev/lib/libstdc++.a(eh_globals.o)(.text+0xf5):eh_globals.cc: undefined reference to `_imp__TlsGetValue@4'
    C:/development/dev/lib/libstdc++.a(eh_globals.o)(.text+0x107):eh_globals.cc: undefined reference to `_imp__SetLastError@4'
    C:/development/dev/lib/libstdc++.a(eh_globals.o)(.text+0x19e):eh_globals.cc: undefined reference to `_imp__GetLastError@0'
    C:/development/dev/lib/libstdc++.a(eh_globals.o)(.text+0x1af):eh_globals.cc: undefined reference to `_imp__TlsGetValue@4'
    C:/development/dev/lib/libstdc++.a(eh_globals.o)(.text+0x1c1):eh_globals.cc: undefined reference to `_imp__SetLastError@4'
    C:/development/dev/lib/libstdc++.a(eh_globals.o)(.text+0x289):eh_globals.cc: undefined reference to `InterlockedIncrement@4'
    C:/development/dev/lib/libstdc++.a(eh_globals.o)(.text+0x2a5):eh_globals.cc: undefined reference to `_imp__Sleep@4'
    ...
    C:/development/dev/lib/gcc/mingw32/3.4.2/libgcc.a(gthr-win32.o)(.text+0x178): undefined reference to `_imp__GetLastError@0'
    C:/development/dev/lib/gcc/mingw32/3.4.2/libgcc.a(gthr-win32.o)(.text+0x1be): undefined reference to `_imp__CreateSemaphoreA@16'
    C:/development/dev/lib/gcc/mingw32/3.4.2/libgcc.a(gthr-win32.o)(.text+0x1de): undefined reference to `InterlockedIncrement@4'
    C:/development/dev/lib/gcc/mingw32/3.4.2/libgcc.a(gthr-win32.o)(.text+0x201): undefined reference to `_imp__WaitForSingleObject@8'
    C:/development/dev/lib/gcc/mingw32/3.4.2/libgcc.a(gthr-win32.o)(.text+0x210): undefined reference to `InterlockedDecrement@4'
    C:/development/dev/lib/gcc/mingw32/3.4.2/libgcc.a(gthr-win32.o)(.text+0x23e): undefined reference to `InterlockedDecrement@4'
    C:/development/dev/lib/gcc/mingw32/3.4.2/libgcc.a(gthr-win32.o)(.text+0x262): undefined reference to `_imp__ReleaseSemaphore@12'
    C:/development/dev/lib/gcc/mingw32/3.4.2/libgcc.a(_eprintf.o)(.text+0x2e): undefined reference to `fprintf'
    C:/development/dev/lib/gcc/mingw32/3.4.2/libgcc.a(_eprintf.o)(.text+0x3e): undefined reference to `fflush'
    make: *** [test] Error 1

  3. #18
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    If you use the -v or --verbose flags when linking/compiling you'll get a lot more information about those processes, which may be of some use to you.

    Interestingly, if you don't invoke ld directly the issue of mangling you describe doesn't seem to be a problem; it seems that when you invoke ld directly as you are attempting to do, you have to specify just about everything and anything, including taking care that the order of switches etc. is correct.

    Good luck, though.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #19
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Very helpful I think! So close! Makefile

    Code:
    LIBPATH   = -L"c:/development/dev/lib" \
    			-L"c:/development/dev/lib/gcc/mingw32/3.4.2"
    
    LIBS      = -lstdc++ -lmingw32 -lgcc -lmsvcrt -luser32 -lkernel32
    
    OBJS      = test.o util.o c:/development/dev/lib/crt1.o \
                c:/development/dev/lib/gcc/mingw32/3.4.2/crtbegin.o \
    			c:/development/dev/lib/gcc/mingw32/3.4.2/crtend.o
    
    LDFLAGS   = --subsystem windows $(LIBPATH) $(LIBS)
    Errors:

    Code:
    test.o(.text+0x15c):test.cpp: undefined reference to `GetStockObject@4'
    c:/development/dev/lib/crt1.o(.text+0x13d):crt1.c: undefined reference to `__GetMainArgs'
    c:/development/dev/lib/crt1.o(.text+0x1b7):crt1.c: undefined reference to `_imp___fmode_dll'
    c:/development/dev/lib/crt1.o(.text+0x1c7):crt1.c: undefined reference to `_imp___environ_dll'
    make: *** [test] Error 1

  5. #20
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    It works.

    Code:
    LIBPATH   = -L"c:/development/dev/lib" \
    			-L"c:/development/dev/lib/gcc/mingw32/3.4.2"
    
    LIBS      = -lstdc++ -lmingw32 -lgcc -lmsvcrt -luser32 -lkernel32 -lgdi32 \
    			-lcrtdll
    
    OBJS      = test.o util.o c:/development/dev/lib/crt1.o \
                c:/development/dev/lib/gcc/mingw32/3.4.2/crtbegin.o \
    			c:/development/dev/lib/gcc/mingw32/3.4.2/crtend.o
    
    LDFLAGS   = --subsystem windows $(LIBPATH) $(LIBS)
    Fun fun fun fun fun in the sun.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. How to combine a GUI with a program
    By bikr692002 in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2006, 07:09 PM
  3. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  4. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM