Migrating from Qt Creator: Xcode does not find Qt-library (Mac)
I am trying to run an academic traffic simulator written in C++/Qt on Xcode, which is struggling to find the necessary Qt library:
I can successfully compile the traffic simulator in Qt Creator (v4.1) as a library (TEMPLATE = lib). If I try to compile the same code as a standalone executable (TEMPLATE = app), I get a "linker error" of the form "symbol(s) not found for architecture x86_64; linker command failed with exit code 1."
Following this error, I have been recommended to use Xcode. In Xcode, the same code does not compile as it does not find the required Qt library. Specifically, in my case, I get the error 'qcolor.h file not found.' If I comment this out, the next Qt-related file cannot be found.
On the web, I've found disappointingly little information about running Qt-based code on Xcode. Where are my Qt libraries installed on the Mac, and how can I tell Xcode about it?
I'm using Xcode 7.2.1 on macOS 10.10.5 (Yosemite) with Qt 4.8.6. (The traffic simulator is not compatible yet with Qt 5.) I'm using clang in Qt Creator. I have installed Qt using the automatic installer available for Mac. (I had also tried building it myself from the source code, but gave up due to a "cc1plus: error: unrecognized command line option ‘-fconstant-cfstrings’" error.) I'm new to Qt and Xcode, but have extensive experience with other programming languages (Java, Python, some C++, all using Eclipse).
Any help is most highly appreciated.
Hi and welcome to devnet,
How did you create the Xcode project ?
Also note that you should get Qt 4.8.7
Thank you very much for your answer, Samuel. I've upgraded to Qt 4.8.7. I'm now able to build the project in Xcode. I think previously I've been creating the Xcode project in the wrong way.
In case someone else is having the same issue, here's what I did:
The path of my project file is ~/Desktop/mezzo_lib/mezzo_lib.pro, and the header and source files (*.h, .cpp) are located in ~/Desktop/mezzo_lib/src/.
My project file reads as follows:
TEMPLATE = lib CONFIG += staticlib debug TARGET = mezzo_lib DEPENDPATH += . src INCLUDEPATH += $(QTDIR)/include LIBS+= -L$(QTDIR)/lib -lQtCore -lQtGui QT+= core gui QMAKE= $(QTDIR)/bin/qmake # here definition of header and source files (not shown)
The steps taken to generate the Xcode project are as follows:
(0) cd to ~/Desktop/mezzo_lib/
(i) qmake -o makefile mezzo_lib.pro
(ii) qmake mezzo_lib.pro -r -spec unsupported/macx-clang CONFIG+=x86_64
(iii) qmake &&make
(iv) qmake -spec macx-xcode
This creates a file mezzo_lib.xcodeproj which can be opened in Xcode by double-clicking. Credits for this solution are due to http://www.qtcentre.org/threads/53249-Setting-QT-in-Xcode-step-by-step-guide . Note that I'm using clang instead of g++.
Is that project code accessible somewhere ?
Having to fiddle with
QMAKElooks more than suspicious.
Also, if possible, you should rather port the code base to Qt 5.
Thanks a lot for your reply and help! The project is open-source. I have uploaded the necessary code on https://github.com/flurinus/transit (the original version of the code is available on a different GitHub repository, which however requires an invitation) . Of course you're more than welcome to have a look at the code.
I am able to build a library of the transit model, but still fail to generate a standalone executable on macOS. I have opened a separate thread for this to keep things as clear as possible.
I don't know if it would be difficult to upgrade to Qt5. If it's easy, it may indeed be a good idea. I however though it'd be easier to first get the current version of the code running on macOS, before starting to change it.
Thanks a lot in advance for any further comments you may have!
This is just to let you know that the code is in fact already compatible with Qt5. I've tested it, and all works out of the box. This is probably due to the fact that the simulator only has a simple GUI, and only makes use of basic Qt features. I can't tell for sure though, since I've not written the code myself.
I also realized that the *.pro-file can be greatly shortened (I've recursively tried removing lines and checking if the library can still be built). Apparently, it can be shortened to the following:
TEMPLATE = lib CONFIG += staticlib debug #comment: the 'debug' is not necessary, staticlib however is TARGET = mezzo_lib DEFINES += _BUSES #this is specific to the simulator # inclusion of source and header files follows here
I hope this makes the code appear in a better light. As described in this thread, I'm still stuck with building a standalone executable ('app') from the code due to a linker error. Interestingly, I get the same linker error when building the library discussed in this thread if I leave away the option
CONFIG += staticlib. I don't know what this option exactly does, and how it could be applied to an 'app', so if you have any thoughts on that, that would be highly appreciated.
Thanks a lot for any comments you may have. I really appreciate.
Not only the .pro file needs cleanup.
Building the code generates an enormous amount of warnings.