Results 1 to 2 of 2

Thread: gfortran + Qt works for X11/Linux but not for minGW under windows XP

  1. #1
    Join Date
    Apr 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default gfortran + Qt works for X11/Linux but not for minGW under windows XP

    gfortran works perfectly with Qt under Fedora12. But it does not work properly with minGW/Msys under windows XP.

    Here is the modified example from qt/examples/opengl/grabber

    f90main.f
    Qt Code:
    1. program f90main
    2. !-------------------------------------------------------
    3. ! Apr-05-2010 V1.0.0 Apr-05-2004 File: f90main.f
    4. !-------------------------------------------------------
    5.  
    6. implicit none
    7.  
    8. integer (2) :: i,iargc
    9. integer (4) :: Narg
    10. character (80) :: Farg(5)
    11.  
    12. !---get fortran command-line arguments
    13. Narg = iargc()
    14. do i=1,Narg
    15. call getarg (i,Farg(i))
    16. end do
    17.  
    18. call Qtmain (Narg,Farg)
    19.  
    20. END program f90main
    To copy to clipboard, switch view to plain text mode 

    qtmain.cpp
    Qt Code:
    1. /******************************************************
    2.   Apr-05-2010 V1.0.0 Apr-05-2010 File: qtmain.cpp
    3. ******************************************************/
    4.  
    5. #include <QApplication>
    6.  
    7. #include "mainwindow.h"
    8.  
    9. extern "C" {
    10.  
    11. MainWindow *qt ;
    12.  
    13. void qtmain_ (int *argc, char *argv[]) {
    14.  
    15. QApplication app(*argc, argv);
    16. MainWindow mainWin;
    17. qt = &mainWin;
    18. mainWin.show();
    19. app.exec();
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

    makefile for minGW/Msys under windows XP
    Qt Code:
    1. prog = f90main
    2.  
    3. F90 = gfortran
    4. F90FLAGS = -m32 -O2 -ffree-line-length-0 -ffree-form
    5.  
    6. LINK = gfortran
    7.  
    8. f90Objects = f90main.o
    9.  
    10. Qt = /mingw/Qt/4.6.2
    11.  
    12. CC = gcc
    13. CXX = g++
    14. DEFINES = -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_EVAL -DQT_DLL -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_
    15. NEEDS_QMAIN
    16. CFLAGS = -m32 -O2 -Wall $(DEFINES)
    17. CXXFLAGS = -m32 -O2 -frtti -fexceptions -mthreads -Wall $(DEFINES)
    18. INCPATH = -I'c:/minGW/Qt/4.6.2/include/QtCore' -I'c:/minGW/Qt/4.6.2/include/QtGui' -I'c:/minGW/Qt/4.6.2/include/QtOpenGL' -I'c:/minGW/Qt/4.6.2/i
    19. nclude' \
    20. -I'c:/minGW/Qt/4.6.2/include/ActiveQt' -I'tmp/moc/release_shared' -I'c:/minGW/Qt/4.6.2/mkspecs/win32-g++'
    21.  
    22. LFLAGS = -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -mthreads -Wl -Wl,-subsystem,windows
    23. LIBS = -L'c:/minGW/Qt/4.6.2/lib' -lstdc++ -lopengl32 -lglu32 -lgdi32 -luser32 -lmingw32 -lqtmain -lQtOpenGL4 -lQtGui4 -lQtCore4
    24.  
    25. ####### Files
    26. SOURCES = qtmain.cpp glwidget.cpp mainwindow.cpp moc_glwidget.cpp moc_mainwindow.cpp
    27. OBJECTS = qtmain.o glwidget.o mainwindow.o moc_glwidget.o moc_mainwindow.o
    28. TARGET = $(prog).exe
    29.  
    30. MOC = $(Qt)/bin/moc
    31.  
    32. ####### Implicit rules
    33. .SUFFIXES: .o .c .cpp .cc .cxx .C .f .h
    34.  
    35. .f.o:
    36. $(F90) -c $(F90FLAGS) $(F90INCPATH) -o $@ $<
    37.  
    38. .cpp.o:
    39. $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
    40.  
    41. .cc.o:
    42. $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
    43.  
    44. .cxx.o:
    45. $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
    46.  
    47. .C.o:
    48. $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
    49.  
    50. .c.o:
    51. $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
    52.  
    53.  
    54. ####### Build rules
    55. $(TARGET): $(f90Objects) $(OBJECTS)
    56. $(LINK) $(LFLAGS) -o $(TARGET) $(f90Objects) $(OBJECTS) $(LIBS)
    57.  
    58. ####### moc
    59. moc_glwidget.cpp: glwidget.h
    60. $(MOC) $(DEFINES) $(INCPATH) glwidget.h -o moc_glwidget.cpp
    61.  
    62. moc_mainwindow.cpp: mainwindow.h
    63. $(MOC) $(DEFINES) $(INCPATH) mainwindow.h -o moc_mainwindow.cpp
    64.  
    65. moc_glwidget.o: moc_glwidget.cpp mainwindow.h
    66. moc_window.o: moc_window.cpp mainwindow.h
    67.  
    68. all: $(TARGET)
    69.  
    70. clean:
    71. rm *.o
    72. rm moc*.cpp
    To copy to clipboard, switch view to plain text mode 

    For GNU Fortran (GCC) 4.4.3 under fedora12 with Qt 4.6.2, it works fine. But with GNU Fortran (GCC) 4.4.0 and GNU make 3.81 with Qt 4.6.2 under minGW/Msys/windows XP, it gave the errors:

    Qt Code:
    1. c:/minGW/Qt/4.6.2/lib/libqtmain.a(qtmain_win.o):qtmain_win.cpp:(.text+0x131): undefined reference to `qMain(int, char**)'
    2. collect2: ld returned 1 exit status
    3. make: *** [f90main.exe] Error 1
    To copy to clipboard, switch view to plain text mode 

    Is there a walk-around solution for this problem?
    Thanks

  2. #2
    Join Date
    Apr 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: gfortran + Qt works for X11/Linux but not for minGW under windows XP

    After searching web for solution, it turned out the error was caused by a missing main() routine under the minGW/MSYS environment.

    If the 'qtmain.cpp' is replaced by
    Qt Code:
    1. /******************************************************
    2.   Apr-05-2010 V1.0.0 Apr-05-2010 File: qtmain.cpp
    3. ******************************************************/
    4.  
    5. #include <QApplication>
    6.  
    7. #include "mainwindow.h"
    8. #include <iostream>
    9. #include <string.h>
    10.  
    11. using namespace std;
    12.  
    13. int main (int argc, char *argv[]) {
    14.  
    15. QApplication app(argc, argv);
    16. MainWindow mainWin;
    17. mainWin.show();
    18. return app.exec();
    19. }
    20.  
    21. extern "C" {
    22.  
    23. void qtmain_ () {
    24. int argc = 0;
    25. char argv[0][0];
    26. main (argc,(char**)argv);
    27. }
    28.  
    29. }
    To copy to clipboard, switch view to plain text mode 

    the compilation went through. However, the f90 main program 'f90main.f' was never executed since the entry point go directly to main() while running 'f90main.exe'.

    Now the question is why under minGW/MSYS Qt requires a main() routine?
    Is it a bug or the nature of windows system?
    Also, is it a way to instruct GNU loader 'ld' to start from Fortran's main program?

    Thanks.

Similar Threads

  1. Works well on Windows but fails on Linux
    By utkuaydin in forum Qt Programming
    Replies: 3
    Last Post: 11th January 2010, 14:22
  2. Replies: 3
    Last Post: 11th November 2009, 15:24
  3. Replies: 1
    Last Post: 4th November 2009, 23:14
  4. QPalette works differently on windows and linux
    By babu198649 in forum Newbie
    Replies: 3
    Last Post: 6th March 2008, 08:27
  5. Project won't compile under Windows (works under Linux)
    By philski in forum Qt Programming
    Replies: 7
    Last Post: 14th September 2006, 16:29

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.