PDA

View Full Version : compiling for Windows



timmu
23rd October 2012, 21:38
I have a console application that produces a text file and a jpg image. It works fine under Linux but under Windows the jpg file is empty (0 kb). I'm using Qt4.4.3. My Linux Qt is dynamic, my windows Qt is static (built statically).

This is my *.pro file.


TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .

# Input
HEADERS += functions.cpp
SOURCES += functions.cpp main.cpp


Trying to make the program to work under Windows I changed my *.pro file to this:


TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .

# Input
HEADERS += functions.cpp
SOURCES += functions.cpp main.cpp
CONFIG += console
CONFIG += staticlib
QTPLUGIN += qjpeg \
qgif \
qtiff \
qmng


..but still the program cannot produce a jpg file under Windows.

Could anyone suggest what else I could try? I would really appreciate any help.

My Makefile is this, in case that helps:


first: all
install: debug-install release-install
uninstall: debug-uninstall release-uninstall
MAKEFILE = Makefile
QMAKE = c:\Qt\4.4.3\bin\qmake.exe
DEL_FILE = del
CHK_DIR_EXISTS= if not exist
MKDIR = mkdir
COPY = copy /y
COPY_FILE = $(COPY)
COPY_DIR = xcopy /s /q /y /i
INSTALL_FILE = $(COPY_FILE)
INSTALL_PROGRAM = $(COPY_FILE)
INSTALL_DIR = $(COPY_DIR)
DEL_FILE = del
SYMLINK =
DEL_DIR = rmdir
MOVE = move
CHK_DIR_EXISTS= if not exist
MKDIR = mkdir
SUBTARGETS = \
debug \
release

debug: $(MAKEFILE).Debug FORCE
$(MAKE) -f $(MAKEFILE).Debug
debug-make_default: $(MAKEFILE).Debug FORCE
$(MAKE) -f $(MAKEFILE).Debug
debug-make_first: $(MAKEFILE).Debug FORCE
$(MAKE) -f $(MAKEFILE).Debug first
debug-all: $(MAKEFILE).Debug FORCE
$(MAKE) -f $(MAKEFILE).Debug all
debug-clean: $(MAKEFILE).Debug FORCE
$(MAKE) -f $(MAKEFILE).Debug clean
debug-distclean: $(MAKEFILE).Debug FORCE
$(MAKE) -f $(MAKEFILE).Debug distclean
debug-install: $(MAKEFILE).Debug FORCE
$(MAKE) -f $(MAKEFILE).Debug install
debug-uninstall: $(MAKEFILE).Debug FORCE
$(MAKE) -f $(MAKEFILE).Debug uninstall
release: $(MAKEFILE).Release FORCE
$(MAKE) -f $(MAKEFILE).Release
release-make_default: $(MAKEFILE).Release FORCE
$(MAKE) -f $(MAKEFILE).Release
release-make_first: $(MAKEFILE).Release FORCE
$(MAKE) -f $(MAKEFILE).Release first
release-all: $(MAKEFILE).Release FORCE
$(MAKE) -f $(MAKEFILE).Release all
release-clean: $(MAKEFILE).Release FORCE
$(MAKE) -f $(MAKEFILE).Release clean
release-distclean: $(MAKEFILE).Release FORCE
$(MAKE) -f $(MAKEFILE).Release distclean
release-install: $(MAKEFILE).Release FORCE
$(MAKE) -f $(MAKEFILE).Release install
release-uninstall: $(MAKEFILE).Release FORCE
$(MAKE) -f $(MAKEFILE).Release uninstall

Makefile: bitwalk.pro ../../.qmake.cache c:/Qt/4.4.3/mkspecs/win32-g++/qmake.conf c:/Qt/4.4.3/mkspecs/features/exclusive_builds.prf \
c:/Qt/4.4.3/mkspecs/features/default_pre.prf \
c:/Qt/4.4.3/mkspecs/features/win32/default_pre.prf \
../../.qmake.cache \
../../mkspecs/qconfig.pri \
c:/Qt/4.4.3/mkspecs/features/qt_functions.prf \
c:/Qt/4.4.3/mkspecs/features/qt_config.prf \
c:/Qt/4.4.3/mkspecs/features/debug.prf \
c:/Qt/4.4.3/mkspecs/features/debug_and_release.prf \
c:/Qt/4.4.3/mkspecs/features/default_post.prf \
c:/Qt/4.4.3/mkspecs/features/staticlib.prf \
c:/Qt/4.4.3/mkspecs/features/static.prf \
c:/Qt/4.4.3/mkspecs/features/win32/console.prf \
c:/Qt/4.4.3/mkspecs/features/win32/rtti.prf \
c:/Qt/4.4.3/mkspecs/features/win32/stl.prf \
c:/Qt/4.4.3/mkspecs/features/warn_on.prf \
c:/Qt/4.4.3/mkspecs/features/qt.prf \
c:/Qt/4.4.3/mkspecs/features/win32/thread.prf \
c:/Qt/4.4.3/mkspecs/features/moc.prf \
c:/Qt/4.4.3/mkspecs/features/win32/exceptions_off.prf \
c:/Qt/4.4.3/mkspecs/features/resources.prf \
c:/Qt/4.4.3/mkspecs/features/uic.prf \
c:/Qt/4.4.3/mkspecs/features/yacc.prf \
c:/Qt/4.4.3/mkspecs/features/lex.prf \
c:/Qt/static/lib/QtGuid.prl \
c:/Qt/static/lib/QtCored.prl
$(QMAKE) -win32 -o Makefile bitwalk.pro
c:\Qt\4.4.3\mkspecs\features\exclusive_builds.prf:
c:\Qt\4.4.3\mkspecs\features\default_pre.prf:
c:\Qt\4.4.3\mkspecs\features\win32\default_pre.prf :
..\..\.qmake.cache:
..\..\mkspecs\qconfig.pri:
c:\Qt\4.4.3\mkspecs\features\qt_functions.prf:
c:\Qt\4.4.3\mkspecs\features\qt_config.prf:
c:\Qt\4.4.3\mkspecs\features\debug.prf:
c:\Qt\4.4.3\mkspecs\features\debug_and_release.prf :
c:\Qt\4.4.3\mkspecs\features\default_post.prf:
c:\Qt\4.4.3\mkspecs\features\staticlib.prf:
c:\Qt\4.4.3\mkspecs\features\static.prf:
c:\Qt\4.4.3\mkspecs\features\win32\console.prf:
c:\Qt\4.4.3\mkspecs\features\win32\rtti.prf:
c:\Qt\4.4.3\mkspecs\features\win32\stl.prf:
c:\Qt\4.4.3\mkspecs\features\warn_on.prf:
c:\Qt\4.4.3\mkspecs\features\qt.prf:
c:\Qt\4.4.3\mkspecs\features\win32\thread.prf:
c:\Qt\4.4.3\mkspecs\features\moc.prf:
c:\Qt\4.4.3\mkspecs\features\win32\exceptions_off. prf:
c:\Qt\4.4.3\mkspecs\features\resources.prf:
c:\Qt\4.4.3\mkspecs\features\uic.prf:
c:\Qt\4.4.3\mkspecs\features\yacc.prf:
c:\Qt\4.4.3\mkspecs\features\lex.prf:
c:\Qt\static\lib\QtGuid.prl:
c:\Qt\static\lib\QtCored.prl:
qmake: qmake_all FORCE
@$(QMAKE) -win32 -o Makefile bitwalk.pro

qmake_all: FORCE

make_default: debug-make_default release-make_default FORCE
make_first: debug-make_first release-make_first FORCE
all: debug-all release-all FORCE
clean: debug-clean release-clean FORCE
distclean: debug-distclean release-distclean FORCE
-$(DEL_FILE) Makefile

debug-mocclean: $(MAKEFILE).Debug
$(MAKE) -f $(MAKEFILE).Debug mocclean
release-mocclean: $(MAKEFILE).Release
$(MAKE) -f $(MAKEFILE).Release mocclean
mocclean: debug-mocclean release-mocclean

debug-mocables: $(MAKEFILE).Debug
$(MAKE) -f $(MAKEFILE).Debug mocables
release-mocables: $(MAKEFILE).Release
$(MAKE) -f $(MAKEFILE).Release mocables
mocables: debug-mocables release-mocables
FORCE:

$(MAKEFILE).Debug: Makefile
$(MAKEFILE).Release: Makefile

wysota
23rd October 2012, 22:44
My guess is you don't have an imageformat plugin for JPEG in your static Windows build.

timmu
24th October 2012, 04:45
Hi,

Actually I do have this imageformat plugin. I've used the same static build numerous times with GUI and it can create static applications that can great jpg just fine. The exe file of my simple script is 7 MB which also shows that the plugins were incorporated.

Some parts of my main.cpp look like this:


#include <QApplication>
#include <QCoreApplication>

int main(int argc, char *argv[])
{


//QCoreApplication application(argc, argv);
QApplication application(argc, argv);

//other functions
}


I'm actually not sure if I should use QApplication or QCoreApplication for this console program? Could this issue have something to do with not being able to create jpg?

Any other suggestions are most welcome as I really need to get this to work. I reduced my script down to just a few lines that create an empty image. It still works under Linux but not under Windows. Does anyone have a very simple example code that is known to work (makes a jpg) with static compilation under Windows? Especially the pro file. Thanks.

wysota
24th October 2012, 08:14
Does it work if you create a png file instead of jpeg?

timmu
24th October 2012, 09:01
Thanks, Wysota for an interesting hint.

Indeed it works will with png. It has no problem making png image.
It can also make BMP image just fine and all this regardless whether I use
QApplication or QCoreApplication in my main.cpp.

What does this mean?

wysota
24th October 2012, 09:06
It means you don't have a working JPEG static plugin. See what QImageWriter::supportedImageFormats() returns.

timmu
24th October 2012, 09:12
Thanks again.
I think I could use some help with running this QImageWriter::supportedImageFormats() test. Would you be able to help with more details as to what exactly I should put in my code? Thanks!

In my /plugins/imageformats folder I have libqjpeg.a and libqjpegd.a. Does that mean that I have the plugins?

wysota
24th October 2012, 10:47
I think I could use some help with running this QImageWriter::supportedImageFormats() test. Would you be able to help with more details as to what exactly I should put in my code? Thanks!

int main(int argc, char **argv) {
QApplication app(argc, argv);
qDebug() << QImageWritter::supportedImageFormats();
return 0;
}


In my /plugins/imageformats folder I have libqjpeg.a and libqjpegd.a. Does that mean that I have the plugins?

Maybe yes, maybe not. They look like image plugins and it looks like you are linking them in your project but maybe you are not creating their instances in your program.

Try adding a Q_IMPORT_PLUGIN(qjpeg) line in your code.

This will make my above snippet look like:


#include <QtGui>
Q_IMPORT_PLUGIN(qjpeg)

int main(int argc, char **argv) {
QApplication app(argc, argv);
qDebug() << QImageWritter::supportedImageFormats();
return 0;
}

timmu
24th October 2012, 12:28
Thank you so much, Wysota! You are alays so helpful!

Indeed I forgot to add Q_IMPORT_PLUGIN(qjpeg)

All I had to do now was include <QtPlugin> and do "make clean"
and everything worked like magic!