PDA

View Full Version : Qt4 MacOSX UB Xcode and a static Qt build?



kuroyume0161
17th March 2007, 07:03
As the forum says: I am a Qt newbie and not a Mac developer whiz (most of my development experience is Amiga/MSDOS/Windows+Java), so please bear with my naive ignorance. :)

Alright, I have an Intel mac with MacOS 10.4.9 and Xcode 2.4.1 installed. I've just finished installing Qt and making the static Qt so that the project app can be a consolidated unit. All that I have for this project is the source code as provided by the developer who wrote this for Windows - I am attempting to port it to Mac (gulp).

I ran 'qmake -spec macx-xcode (project).pro' to get a .pro for the source. The resulting .xcodeproject is opened with Xcode but there is no static Qt lib added - only the frameworks. Do I need to specify a set of the Qt static libs - in addition to or instead of the Qt frameworks?

Also, there are warnings and errors - the errors are ALL about OpenGL type 'const GLuint*'. OpenGL is specified in the .pro file (QT += opengl) and the OpenGL frameworks are included: OpenGL and QtOpenGL.

It seems that there is diminishing information concerning Mac Qt builds - especially for how to accomplish a static app from Xcode. Would the built examples help at all (from 'sudo make install')? I am not someone who likes command line build for development - NetBeans, SunOne, VS, Xcode, CodeWarrior - give me an IDE not a stack of commands and configuration files. :o

Thank you very much,

Robert

jacek
17th March 2007, 17:33
Also, there are warnings and errors - the errors are ALL about OpenGL type 'const GLuint*'. OpenGL is specified in the .pro file (QT += opengl) and the OpenGL frameworks are included: OpenGL and QtOpenGL.
Do you have the OpenGL library and its headers installed on your system?

Brandybuck
17th March 2007, 20:08
Alright, I have an Intel mac with MacOS 10.4.9 and Xcode 2.4.1 installed. I've just finished installing Qt and making the static Qt so that the project app can be a consolidated unit. All that I have for this project is the source code as provided by the developer who wrote this for Windows - I am attempting to port it to Mac (gulp).
You can find some helpful information on the Assistant pages "Deploying an Application on Qt/Mac" and "Qt/Mac-Specific Issues".

I have lots more advice for building statically linked Mac applications, but I only know how to do it from the command line. So I'm afraid I can't help you there.

kuroyume0161
17th March 2007, 23:11
Do you have the OpenGL library and its headers installed on your system?

How do I know? I have Xcode 2.4.1 which contains all of the frameworks/includes/libs for building Mac applications.

This is difficult since the Wiki-Build Systems here for "Building static Qt on Mac" is empty.

kuroyume0161
17th March 2007, 23:15
You can find some helpful information on the Assistant pages "Deploying an Application on Qt/Mac" and "Qt/Mac-Specific Issues".

I have lots more advice for building statically linked Mac applications, but I only know how to do it from the command line. So I'm afraid I can't help you there.

You can go ahead and provide the advice :) as it seems that building with Xcode is not recommended (nor is it described in any detail).

For instance, here is my .pro file. Whenever I run 'qmake -makefile -o makefile my.pro', it produces an xcode project - for the command line I would think that I want a makefile for make, correct?

################################################## ####################
# Automatically generated by qmake (2.01a) Fri Mar 16 01:30:51 2007
################################################## ####################

TEMPLATE = app
DESTDIR = /Users/RobertTempleton/Data/IvyGenerator/IvyGenerator/bin
TARGET = ivygenerator
DEPENDPATH += .
INCLUDEPATH += .
QT += opengl
# QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk
CONFIG += qt release static x86 ppc
QMAKE_LIBS_QT =
QMAKE_LIBS_QT_THREAD =
LIBS += $(QTDIR)/lib/libqtcore.a $(QTDIR)/lib/libqtgui.a $(QTDIR)/lib/libqtopengl.a -lz -framework Carbon


# Input
HEADERS += BasicMesh.h \
Camera.h \
Common.h \
GLee.h \
Ivy.h \
ivygenerator.h \
OBJLoader.h \
OBJWriter.h \
RenderWidget.h \
SetupWidget.h \
Vector2d.h \
Vector3d.h
SOURCES += BasicMesh.cpp \
Camera.cpp \
Common.cpp \
GLee.c \
Ivy.cpp \
ivygenerator.cpp \
main.cpp \
OBJLoader.cpp \
OBJWriter.cpp \
RenderWidget.cpp \
SetupWidget.cpp


Just for clarity's sake, I did make a universal static release build of the Qt libs.

Thanks, Robert

jacek
17th March 2007, 23:39
How do I know?
Sorry, by I don't have a slightest idea. I would look for OpenGL headers, for example gl.h.


"Building static Qt on Mac" is empty.
It looks like you will have to fill it. ;)

kuroyume0161
18th March 2007, 00:03
Sorry, by I don't have a slightest idea. I would look for OpenGL headers, for example gl.h.

The only place that I've found the OpenGL headers/libs is under X11 - I suspect that these are the ones that need to be considered somehow. How, I have no clue. I would have figured that the QT+=opengl would have considered this for MacOS development - but guess not.


It looks like you will have to fill it. ;)

:)

Some more fiddling to do...

Thanks,
Robert

jacek
18th March 2007, 01:19
I would have figured that the QT+=opengl would have considered this for MacOS development - but guess not.
This would work only if those headers were in a standard place. According to $QTDIR/mkspecs/macx-xcode/qmake.conf, qmake will look for them in /System/Library/Frameworks/OpenGL.framework/Headers and /System/Library/Frameworks/AGL.framework/Headers.

kuroyume0161
18th March 2007, 02:02
This would work only if those headers were in a standard place. According to $QTDIR/mkspecs/macx-xcode/qmake.conf, qmake will look for them in /System/Library/Frameworks/OpenGL.framework/Headers and /System/Library/Frameworks/AGL.framework/Headers.

Hmmm - and there they are: gl.h, glext.h, glu.h. And these will also be available in /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/... for Xcode.

I've not been able to get this to work with either make or XCode (note that to make a makefile and not an Xcode project, needed to do 'qmake -spec macx-g++' instead of 'qmake -spec macx-xcode' - so now I have both at my disposal). The same errors on const GLuint* which doesn't make sense.

Now, to fill this in a little. This project does use GLee - I am not using the library just the source. Could it be GLee creating difficulties? Though I suspect that glDeleteTextures() is an OpenGL, not a GLee, call.

Thanks,
Robert

jacek
18th March 2007, 02:11
The same errors on const GLuint* which doesn't make sense.
Could you post the exact error message (the first one)?

kuroyume0161
18th March 2007, 02:49
Could you post the exact error message (the first one)?

I don't need to! ;)

Hmmm, lemme see. The typedef is to GLuint which one would suppose to be an unsigned int, right? And obviously it worked for the originator in Windows. But, noooo, for Apple it is typedef'd as an unsigned long - and that is all it took to generate these errors!

Sweet mama of yeshua! No problems with OpenGL or anything else - it's simply a matter of casting the bastard values.

Still some errors to work out - like QFrame not being a class or namespace. At least it's now down to Qt related stuff.

I'll be back if things like that can't be resolved.

Thanks!
Robert

jacek
18th March 2007, 03:18
it's simply a matter of casting the bastard values
It depends on whether you are casting unsigned int to GLuint or vice versa. What if sizeof(unsigned long) > sizeof(unsigned int)? I haven't seen your code, but maybe using GLuint instead of casting will be a safer solution?

kuroyume0161
18th March 2007, 03:35
It depends on whether you are casting unsigned int to GLuint or vice versa. What if sizeof(unsigned long) > sizeof(unsigned int)? I haven't seen your code, but maybe using GLuint instead of casting will be a safer solution?

I'm trying not to change *any* of his code - this is not my application, I'm just porting it to Mac since he cannot.

Should not cause any problems as the variable texobj is unsigned int and the cast is to (const GLuint*)&m->texobj. But if it does, I might be able to get away with changing the variable to unsigned long.

Now my problem is this line:

splitter->setFrameShadow(QFrame::Shadow::Sunken);

is generating a compiler error:

error: 'class QFrame::Shadow' is not a class or namespace

(?) It can't possibly be because QtGui is not included (it is both as static lib and #include <QtGui>) as just above it is a mention of QWidget and QSplitter - no errors on them. The compiler doesn't appear to like that QFrame is being used in a static mode to get to these enums. Any ideas?

Thanks,
Robert

kuroyume0161
18th March 2007, 05:06
My thinking here on the QFrame::Shadow and QFrame::Shape errors is that gcc might not be understandin' the concept of something like this:


class QFrame
{
enum Shape
{
...
Panel = 0x0002,
...
}
}

I guess that Visual Studio has no problems with the construct causing the error, but Xcode don't like it.

Should I just hard code the value (yuck) or is there another way to dereference the enum within the class (something that I'm not too familiar with - my enums are always global).

Thanks,
Robert

Brandybuck
18th March 2007, 07:46
You can go ahead and provide the advice :) as it seems that building with Xcode is not recommended (nor is it described in any detail).
Okay. The main problem is that the Mac always wants to link with the frameworks if they are present. The Trolltech "solution" is to move the frameworks out of the way, so that the static libs will be used. I find this annoying for a variety of reasons. What I do instead is to have two separate Qt installations, one with shared frameworks for development, and one with static libs for deployment. Most the time I used the regular framework version, but switch to the other when it's time to bundle stuff up for a release.

Assuming you have a shared framework version installed and working, the next thing to do is to build a static version of Qt. You don't want to build everything though, as you'll use up dozens of gigabytes. You already have Designer, Assistant, etc. in your shared version, so there's no need to build them again. All you want to do now is to build the static libraries and the basic build tools (qmake, moc, uic, rcc).

Download the sources (qt-mac-opensource-src-4.2.3.tar.gz, for this example) and have them in your home directory. Open up a Terminal window. Then extract them to the installation destination with the following commands. I'm using standard directory locations, but you can vary to taste:

sudo mkdir -p /usr/local/Trolltech
cd /usr/local/Trolltech
sudo tar xvzf ~/qt-mac-opensource-src-4.2.3.tar.gz
sudo mv qt-mac-opensource-src-4.2.3 Qt-4.2.3-static
cd Qt-4.2.3-static

Now you need to configure and build for static linking. You may need more configure options that I have used:

sudo ./configure -static -prefix /usr/local/Trolltech/Qt-4.2.3-static -universal -sdk /Developer/SDKs/MacOSX10.4u.sdk
sudo make sub-src

Finally, to easily switch to the static environment, create a short shell script in your home directory. Use a text editor and create a "qtstatic.sh" file with the following:

#!/bin/sh
QMAKESPEC=macx-g++
QTDIR=/usr/local/Trolltech/Qt-4.2.3-static
PATH=$QTDIR/bin:$PATH
export QMAKESPEC QTDIR PATH

Now you're ready to build your app. You have to do this from a Terminal. Replace "src" with the appropriate application source directory:

cd src
. ~/qtstatic.sh
qmake application.pro
make

Statically linked applications need to be stripped, especially those gargantuan universal apps. Replace both "myapplication" with the appropriate app name:

strip myapplication.app/Contents/MacOS/myapplication

To run the application bundle from the command line (should you wish), use the "open" command:

open myapplication.app

I hope this helps. If anyone is ambitious, feel free to clean up these notes and put them on the wiki.

kuroyume0161
18th March 2007, 09:10
Thanks for the info, Brandybuck!

I've already successfully built Qt as a static release universal lib. Since I'm on an Intel Mac, it went smoothly (if not lengthy including the examples).

Thankfully, these compiler errors forced me to dig deeper into qmake and the .pro file so that setup was more suitable for the desired result. It turns out that all of the errors are related to the difference between what Windows and MacOS will allow for certain areas. Once I cast the 'const GLuint*', turned an int into a more proper GLint, and worked around the QFrame::Shadow:: enum stuff the build was successful - in Xcode! And the app runs and works.

A couple of notes about Xcode and the static Qt lib (still waiting for confirmation on the app working on other systems including PPC, so take with grain of salt and parsley for the time being):

0. I used Xcode 2.4.1 and Qt 4.2.3 on MacOS 10.4.9, Intel Mac

1. Remove the Qt frameworks from the xcode project outright and Replace them with the Qt static libs.

2. In the Target Build settings (target->Get Info), remove the header paths to the Qt frameworks and Replace with the general Qt header paths (qt/include - recursive works here).

3. In the same place, change -DQT_SHARED with -DQT_STATIC for both C and C++.

4. Make sure that Library Search Paths includes, for instance, "/Developer/qt/lib". Might not be necessary, but ensures that they are found even though included in the project directly.

The app is 15.5MB (as compared to the 3.2MB Windows app with static Qt lib) so I'm optimistic that it didn't do the Qt frameworks. We'll see whether this is the case from some volunteers.

Thank you all very much and I'll be back if success spills to failure. :)

Robert