Wednesday, December 21, 2011

Qt failed on "configure": on Windows with Visual Studio

When I cloned Qt source code from git, and open a Visual Studio Command Prompt (2010), and went to Qt directory, and run command "configure.exe" to compile the Qt source code, I got the error like something below:
%QTDIR%\src\corelib\global\qglobal.h(62) : fatal error C1083: Cannot open include file: 'QtCore/qconfig.h': No such file or directory...

It's failed on the very beginning when make "qmake". Via process monitor, I verified that actually the qconfig.h has already been created under "%QTDIR%\src\corelib\global\". I have ever compiled the source code from git without any problem. Searched from google, someone mentioned that I need to run "syncqt.bat" from bin folder. syncqt actually is a perl script. Someone replied that don't need to run syncqt.

I tried to install perl, and added perl/bin into my system environment variable path, and then everything works fine. The reason is that "configure.exe" relies on perl script to create the Qt library header structure for development.

Just a clue for anyone who searched related information and come to this page.

Saturday, October 15, 2011

Deploy Application on Mac with dylib as private framework

Qt's tool macdeployqt is excellent for automatic deploy qt applications on Mac. But the limitation is that macdeployqt can works only for your custom frameworks. If you have dylib to be deployed, you'll get some trouble. Here is my script to deploy my library DuckCore with DuckCapture:


macdeployqt release/DuckCapture.app

declare DUCKLIB=libDuckCore.1.dylib
declare DUCKAPP=release/DuckCapture.app
mkdir -p $DUCKAPP/Contents/Frameworks
cp release/$DUCKLIB $DUCKAPP/Contents/Frameworks/$DUCKLIB
install_name_tool -id @executable_path/../Frameworks/$DUCKLIB $DUCKAPP/Contents/Frameworks/$DUCKLIB
install_name_tool -change $DUCKLIB @executable_path/../Frameworks/$DUCKLIB $DUCKAPP/Contents/MacOS/DuckCapture


The main approach is to use the tool "install_name_tool" for dylib, and you'd better to pay more attention to path. It's easy to make mistakes on path in this script.

In addition for releasing, there is another issue for debugging applications with xcode. You can open a console, and run commands below:

export DYLD_PRINT_LIBRARIES=1
open xcode


You'll get some clues when dylib is missing.

Tuesday, February 8, 2011

The case deserves your attention: incorrect checksum for freed object

When I port my free screen capture tool DuckCapure to Mac OS. I got an exception every time when I start to capture the screen. The error message is:
DuckCapture(10059,0x7fff7006aca0) malloc: *** error for object 0x103468168: incorrect checksum for freed object - object was probably modified after being freed.

*** set a breakpoint in malloc_error_break to debug

The program has unexpectedly finished.

I'm very confused with this assertion, the error happens when I use the data member from an internal class called DWidgetData, the constructor is as follows:
    DWidgetData()
        : m_pStyledContainer( NULL )
        , m_pContainerContainer( NULL )
        , m_pLayout( NULL )
        , m_pAnimationFading( NULL )
        , m_pEffectOpacity( NULL )
        , m_pEffectDropShadow( NULL )
    {}

The debugger shows a very strange content for a just initialized DWidgetData object:
Looks like the data corruption, or the constructor is never called. I have another test application which used the same component and passed the test, but DuckCapture failed. I spent hours on this issue, and finally resolved it:

Reason: In dynamic linked library DuckCore, I used forward declaration for DWidgetData in header file, and defined the class in source file. Looks reasonable, huh? However, I happened to define another DWidgetData in DuckCapture also. That's the nightmare. The code in DuckCore used the DWidgetData in DuckCapture instead of the one defined in the source file I used it.

This is another dangerous case on compiler compatibility: Visual Studio 2008/2010 on Windows works, but gcc 4.2 on Mac OS does not.

Monday, February 7, 2011

Qt Creator/qmake compiling issues on Mac and Windows

Qt Creator is the best tool for you to create/maintain cross platform (Mac, Windows, Linux) project files. You can use Qt Creator project file (*.pro) to handle the platform dependent files as well. In addition, there are also slight difference between Windows and Mac when you use qmake.

1. Add platform dependent configures in pro file.


Please refer to the code below:
mac {
ICON = images/app.icns
OBJECTIVE_SOURCES += utils.mm
LIBS += -framework Cocoa
QMAKE_INFO_PLIST = min.us.Info.plist
}
win32 {
SOURCES += \
    utils.cpp
RC_FILE = min.us.rc
}

You can use "mac { ... }" to include any information which is specific to Mac OS. For example, the application icon which is specific for Mac OS, framework, or an Objective-C source file. Someone may use the style "else:win32{ ... }". I prefer the condition without "else:". Please note that "unix { ... }" has already included the case that this is a Mac machine, so if you have something works only on unix, you can use one of the two styles: "unix:!mac { ... }", or "mac { ... } else:unix { ... }"

2. Use qmake to generate makefile or project files for Visual Studio / XCode


qmake is a great command line tool, I used it to generate project files for my favorite IDE on different platforms: Visual Studio on Windows, xCode on Mac OS. I use Qt Creator as my IDE on Ubuntu.

On Windows, the command "qmake -tp vc" can generate vcxproj for Visual Studio 2010 or vcproj file for Visual Studio 2008 depending on your command line environment, or you can specify the version explicit by "-spec" parameter or by setting environment variable "QMAKESPEC". The "qmake -tp vc" means, use the templat prefix "vc" when run qmake for pro file, actually template prefix "vc" means generate Visual C++ project file.

On Mac, you the default behavior of "qmake" just generate xcode project file. So just run "qmake" under the folder with "pro" file.

You may also need to generate make file to make an automated building script. qmake can also do it perfectly. On Windows, the default behavior of "qmake" is to generate makefiles, and then you can follow with "nmake" or "nmake debug"/"nmake release". On mac, if you run "make", you may get the error message "make: *** No targets specified and no makefile found. Stop.", just run the command "qmake -spec macx-g++" to generate makefile: use "spec" parameter to specify the make spec "macx-g++" which will help you to generate makefile.

3. Handle application icons on Mac OS / Windows


On Windows, you need to have an "rc" file, and add an icon file. Please include this rc file for Windows only. On Mac, use the qmake internal variable "ICON' to specify the application icon. Please refer to the sample code above for more details.

4. C/C++ Cocoa/Carbon mixed module:


Sometimes you need to handle mixed module on Mac, that is, you may include Objective-C files in your project file. In Qt 4.7, there is still an issue if you want to generate xcode file. The bug has been logged to Nokia here: QTBUG-7953. Read the details in the bug report to get a solution, or wait for a future release.

Monday, January 17, 2011

Blog Relaunched

After ~2 years of no blogging on libg.org, I decided to relaunch my blog writing. It's a place for me to share my experience on business, user interactive design, programming, internet marketing, as well as my products.

The blogs will mainly include topics below:

  • Tips behind design. When Kelly and I design a feature, we get user requirements, feedbacks, and consider market trends, future directions, and a lot of aspects. We try to make things simple, and make ease-to-use usability. I'd like to share the interesting stories behind feature and user interactive design.

  • Problem resolved. Not only about programming, but also platform (Microsoft Windows, Mac OS, Linux) related issues, my core framework, software deployment, website, and so on.

  • Marketing, Sales, and Business. The final goal is to sell more licenses. There may be tips, experience, success story, or whatever need to share.

  • A formal product site can get more trust from visitors. There should be another place for me to share more information about products. When visitors subscribe the product site, the content of this category will be send.