2010-11-06 43 views
0

我目前通過在電子書「C + GUI編程與Qt 4第二版」中的示例來學習Qt。從OS X終端編譯Qt示例的問題

第一個示例是「Hello World」應用程序。按照示例中的步驟,我已經能夠創建以下文件:

  • hello.cpp,通過輸入提供的代碼。
  • hello.pro,通過使用OS X終端命令「qmake -project」。
  • hello.xcodeproj和info.plist中使用命令 「QMAKE hello.pro」

但是,我無法創建 「hello.app」

命令 「使」 產量:

"make: *** No targets specified and no makefile found. Stop." 

命令 「讓你好」 收益率:

g++  hello.cpp -o hello 
hello.cpp:1:24: error: QApplication: No such file or directory 
hello.cpp:2:18: error: QLabel: No such file or directory 
hello.cpp: In function ‘int main(int, char**)’: 
hello.cpp:6: error: ‘QApplication’ was not declared in this scope 
hello.cpp:6: error: expected `;' before ‘app’ 
hello.cpp:7: error: ‘QLabel’ was not declared in this scope 
hello.cpp:7: error: ‘label’ was not declared in this scope 
hello.cpp:7: error: expected type-specifier before ‘QLabel’ 
hello.cpp:7: error: expected `;' before ‘QLabel’ 
hello.cpp:9: error: ‘app’ was not declared in this scope 
make: *** [hello] Error 1 

雖然我不能CREA使用這兩個命令從終端輸入「hello.app」,我可以通過簡單地打開Xcode並按下「Build and Go」按鈕來創建它。

有人能告訴我爲什麼在這個世界上這兩個命令不起作用嗎?我怎樣才能從終端製作「hello.app」?

謝謝!

回答

0

看起來你沒有在makefile路徑中包含來自Qt SDK的目錄。你還記得運行QMake嗎?

2

我看到qmake已經爲您生成*.xcodeproj文件。嘗試運行xcodebuild而不是make :)

+0

謝謝Magnus Hoff! xcodebuild做了詭計!這就是我需要知道的! – CrazyFileMaker 2010-11-06 20:42:36

+1

另外值得一提的是,如果你想生成makefile而不是xcodeproj,你可以調用qmake -spec macx-g ++ – 2010-11-09 11:12:24

+0

@Kamil Klimek:謝謝。我正在尋找,但不知何故:) – 2010-11-09 11:27:36

0

我建議你下載並安裝Qt SDK。然後熟悉Qt Creator,Qt的IDE。這樣做更容易,因爲所有的框架和文檔都是爲您安裝和配置的。