2013-08-06 88 views
2

我正在嘗試爲我一直在編寫的一組C++文件構建一個GUI,並且我決定嘗試Qt。然而,試圖編譯我添加了Qt組件的文件已被證明是困難的。我使用鐺,與調用使用Qt組件編譯C++代碼

clang++ -std=c++0x -stdlib=libc++ -framework QtGui F/Users/[uname]/Qt5.1.0/5.1.0/clang_64/lib -I/Users/[uname]/Qt5.1.0/5.1.0/clang_64/include -L/Users/[uname]/Qt5.1.0/5.1.0/clang_64/lib -o QT qt.cpp 

而這個作品,如果我只包括

#include "QtGui/QGuiApplication" 

好像我應該是應該使用,不過,

#include <QtGui/QApplication> 

這失敗,出現錯誤

fatal error: 'QtGui/QApplication' file not found 

如果我嘗試包括qpushbutton.h文件,用

#include "QtWidgets/QPushButton" 

我得到一個錯誤:

clang++ -std=c++0x -stdlib=libc++ -framework QtGui -F/Users/[uname]/Qt5.1.0/5.1.0/clang_64/lib -I/Users/[uname]/Qt5.1.0/5.1.0/clang_64/include -L/Users/[uname]/Qt5.1.0/5.1.0/clang_64/lib -v -o QT qt.cpp 
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn) 
Target: x86_64-apple-darwin11.4.2 
Thread model: posix 
"/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.7.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name qt.cpp -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 136 -v -resource-dir /usr/bin/../lib/clang/4.2 -F/Users/[uname]/Qt5.1.0/5.1.0/clang_64/lib -I /Users/[uname]/Qt5.1.0/5.1.0/clang_64/include -fmodule-cache-path /var/folders/lw/wq_l1f1936q0dmc1b_tkp94m0000gn/T/clang-module-cache -stdlib=libc++ -std=c++0x -fdeprecated-macro -fdebug-compilation-dir "[path]" -ferror-limit 19 -fmessage-length 204 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.7.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/lw/wq_l1f1936q0dmc1b_tkp94m0000gn/T/qt-YxX3PY.o -x c++ qt.cpp 
clang -cc1 version 4.2 based upon LLVM 3.2svn default target x86_64-apple-darwin11.4.2 
ignoring nonexistent directory "/usr/include/c++/v1" 
#include "..." search starts here: 
#include <...> search starts here: 
/Users/[uname]/Qt5.1.0/5.1.0/clang_64/lib (framework directory) 
/Users/[uname]/Qt5.1.0/5.1.0/clang_64/include 
/usr/bin/../lib/c++/v1 
/usr/local/include 
/usr/bin/../lib/clang/4.2/include 
/usr/include 
/System/Library/Frameworks (framework directory) 
/Library/Frameworks (framework directory) 
End of search list. 
"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.7.0 -o QT -lcrt1.10.6.o -L/Users/[uname]/Qt5.1.0/5.1.0/clang_64/lib -framework QtGui /var/folders/lw/wq_l1f1936q0dmc1b_tkp94m0000gn/T/qt-YxX3PY.o -lc++ -lSystem /usr/bin/../lib/clang/4.2/lib/darwin/libclang_rt.osx.a -F/Users/[uname]/Qt5.1.0/5.1.0/clang_64/lib 
Undefined symbols for architecture x86_64: 
    "QArrayData::deallocate(QArrayData*, unsigned long, unsigned long)", referenced from: 
    QTypedArrayData<unsigned short>::deallocate(QArrayData*) in qt-YxX3PY.o 
    "QPushButton::QPushButton(QString const&, QWidget*)", referenced from: 
    _main in qt-YxX3PY.o 
    "QPushButton::~QPushButton()", referenced from: 
    _main in qt-YxX3PY.o 
    "QString::fromAscii_helper(char const*, int)", referenced from: 
    QString::QString(char const*) in qt-YxX3PY.o 
    "QWidget::show()", referenced from: 
    _main in qt-YxX3PY.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

我也一直在努力QMAKE,從同一缺失的符號無法從x86_64體系如上述,與qt.pro文件是

QT += core 
QT += gui 
SOURCE += qt.cpp 

的qt.cpp文件本身只是一個示例:

#include <QtGui/QApplication> 
#include <QtGui/QPushButton> 

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

    QApplication app(argc, argv); 

    QPushButton but ("Button"); 
    but.show(); 

    return app.exec(); 
} 

我正在使用的文件需要在C++ 11標準中編譯,我真的不想切換IDE,所以Qt Creator不是理想的解決方案(Qt Creator也會生成缺失的符號錯誤)。

我確定有些東西顯而易見,但我需要儘快繼續在項目的非GUI方面進行工作。

我在MacBook Air 64bit上運行Mac OS 10.7.5。我從Qt站點上提供的Mac Installer安裝了Qt5.1.0。我的clang ++版本是4.2(clang-425.0.28),通過XCode中的命令行工具安裝。

在此先感謝。

+0

你確定你已經安裝了64位的Qt,而不是32位的? – lapk

+0

只有一個適用於Mac的Qt版本,即64位。 –

回答

1

你似乎試圖用Qt 5構建Widget被移動到QtWidgets。

這就是爲什麼你需要改變包括從QtGui到QtWidgets。

最重要的是,你需要添加「小部件」到Qt。另外,core和gui默認存在,所以你應該寫下:QT + =這個特定場景中的小部件。

不確定這是否能解決您的架構相關問題,但這些問題至少是錯誤的。

+0

謝謝你指出。我一直在使用Qt4.8的教程,並試圖用Qt5.1進行編譯。自從我轉換到Qt4.8後,它就像一個魅力。 –