Archive:Development/CMake FAQ (zh TW): Difference between revisions

From KDE TechBase
(Created page with '{{Template:I18n/Language Navigation Bar|Development/CMake FAQ}} == 常見問題 == These are KDE's FAQ for CMake, there is also a CMake FAQ in the [http://www.cmake.org/Wiki/CMa...')
 
m (AnneW moved page Development/CMake FAQ (zh TW) to Archive:Development/CMake FAQ (zh TW) without leaving a redirect: Obsolete)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Template:I18n/Language Navigation Bar|Development/CMake FAQ}}
{{Template:I18n/Language Navigation Bar_(zh_TW)|Development/CMake FAQ}}
== 常見問題 ==
== 常見問題 ==


Line 5: Line 5:


=== 如何讓我最喜歡的編輯器支援 CMake 語法和縮排?===
=== 如何讓我最喜歡的編輯器支援 CMake 語法和縮排?===
Read the CMake Wiki section [http://www.cmake.org/Wiki/CMake_Editors_Support CMake Editors Support].  It describes how to setup Emacs (XEmacs works too), VIM, Kate, KWrite, and KDevelop.
請閱讀CMake Wiki [http://www.cmake.org/Wiki/CMake_Editors_Support CMake 編輯器支援]章節。這裡說明如何設定 Emacs(XEmacs works too)、VIM、Kate、KWrite 和 KDevelop。


=== 我需要在建構過程中產生一些檔案,我該怎麼做? ===
=== 我需要在建構過程中產生一些檔案,我該怎麼做? ===
Use ADD_CUSTOM_COMMAND(). It's explained here in the CMake wiki: [http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_generate_a_source_file_during_the_build.3F  How can I generate a source file during the build]
使用 ADD_CUSTOM_COMMAND()。在 CMake wiki [http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_generate_a_source_file_during_the_build.3F  如何在建構過程中生成原始碼檔案]有解釋


=== I need to build an executable which is used later on during the build to generate files. How do I do this ? ===
=== 我想在建構過程中建立一個稍後使用的可執行檔。我該怎麼做?===
Let's say the executable is called genembed. Then use KDE4_ADD_EXECUTABLE(foo RUN_UNINSTALLED ${fooSources})to create the executable. The RUN_UNINSTALLED option is important, because the executable has to run from the build dir and has to link to the libraries in the builddir. To achieve this, the executable is compiled with RPATH set accordingly and a wrapper shell script, named just like the executable but with the suffix ".sh" is created. This shell scripts sets up LD_LIBRARY_PATH and the calls the actual executable.
假設可執行檔叫 genembed。那麼使用 KDE4_ADD_EXECUTABLE(foo RUN_UNINSTALLED ${fooSources})來建立可執行檔。RUN_UNINSTALLED 選項非常重要,因為可執行檔必須從建構目錄執行,並會連結到建構目錄中的一些函式庫。為了達成這個目的,可執行檔透過 RPATH 設定和 shell 腳本包裝編譯,和執行檔的名稱一樣只是多了個「.sh」。這個 shell 腳本建立 LD_LIBRARY_PATH 並呼叫實際的執行檔。
Use this wrapper shell script in the ADD_CUSTOM_COMMAND() as described above.
 
You can find out the name and exact location by querying the property WRAPPER_SCRIPT. Here's a full example taken from kdelibs/kstyles/keramik/ :
依照上面說明的在 ADD_CUSTOM_COMMAND() 中使用這個 shell 腳本包裝。
<code>
您可以通過查詢 WRAPPER_SCRIPT 來找到名稱和確切的路徑。這裡有一個來自 kdelibs/kstyles/keramik/ 的完整例子:
<syntaxhighlight lang="text">
# build the executable
# build the executable
kde4_add_executable(genembed RUN_UNINSTALLED ${genembed_SRCS})
kde4_add_executable(genembed RUN_UNINSTALLED ${genembed_SRCS})
Line 27: Line 28:
   DEPENDS genembed ${keramikPics}
   DEPENDS genembed ${keramikPics}
)
)
</code>
</syntaxhighlight>


As you can see genembed is also listed as a dependency, this means cmake knows that it has to build the executable genembed before executing this rule.
如你所見 genembed 也做為相賴關係列出。這表示 CMake 知道它應該在執行這些規則之前建構 genembed 執行檔。


=== I don't want to set the -DCMAKE_INSTALL_PREFIX command line option.  Does cmake support the KDEDIR environment variable? ===
=== 我不想設定 -DCMAKE_INSTALL_PREFIX 命令列參數。CMake 是否支援 KDEDIR 環境變數? ===
No.  $KDEDIR is deprecated in KDE 4.
不。KDE 4 反對使用 $KDEDIR。


=== Why do I get compile errors like /usr/lib/qt4/include/QtCore/qstring.h:536: undefined reference to `QString::fromLatin1_helper(char const*, int)'? ===
=== 為什麼我會得到/usr/lib/qt4/include/QtCore/qstring.h:536: undefined reference to `QString::fromLatin1_helper(char const*, int)'之類的編譯錯誤?===
A: If you have an old Qt4 version in your qt/lib directory you must delete the old (4.0.1) files.
如果你有舊版的 Qt 4 在 qt/lib 目錄,你必須刪除這些舊版(4.0.1)檔案。


=== How do I tell cmake to create noisy makefiles?  I want to see the exact commands that are run during the make process. ===
=== 我要怎麼讓 CMake 創建 noisy makefiles?我希望看到 make 過程執行的指令。===
Pass the VERBOSE variable to make, i.e.
 
<code>
傳遞 VERBOSE 變數給 make,例如:
<syntaxhighlight lang="text">
% make VERBOSE=1
% make VERBOSE=1
</code>
</syntaxhighlight>
or
<code>
<syntaxhighlight lang="text">
% VERBOSE=1 make
% VERBOSE=1 make
</code>
</syntaxhighlight>
 
更多細節請查看 CMake wiki:[http://www.cmake.org/Wiki/CMake_FAQ#Is_there_an_option_to_produce_more_.27verbose.27_compiling.3F 有沒有選項可以產生更多的'verbose'編譯?]


For more details see the CMake wiki: [http://www.cmake.org/Wiki/CMake_FAQ#Is_there_an_option_to_produce_more_.27verbose.27_compiling.3F Is there an option to produce more 'verbose' compiling?]
=== 產生的 Makefiles 中沒有 'make distclean' 標籤。我該如何才能清理包括 cache 檔案在內的所有檔案? ===


=== There is no 'make distclean' target in the generated Makefiles.  How do I clean up everything, including the cache files? ===
只需刪除建構目錄,或建構目錄裡的內容。
Simply remove the build directory, or just the contents of the build directory.


=== I've got ''fatal error LNK1104: cannot open file 'optimized.lib' '' under Windows/msvc (release with debug info build)  ===
=== I've got ''fatal error LNK1104: cannot open file 'optimized.lib' '' under Windows/msvc (release with debug info build)  ===
Line 58: Line 61:
'''QT_*_LIBRARIES must not be used''' in your target_link_libraries() line of CMakeLists.txt. Use QT_*_LIBRARY instead. Otherwise the variable will look like this (example for QT_QTNETWORK_LIBRARY):
'''QT_*_LIBRARIES must not be used''' in your target_link_libraries() line of CMakeLists.txt. Use QT_*_LIBRARY instead. Otherwise the variable will look like this (example for QT_QTNETWORK_LIBRARY):


<code>
<syntaxhighlight lang="text">
optimized;C:/kde4/lib/QtNetwork4.lib;debug;C:/kde4/lib/QtNetworkd4.lib
optimized;C:/kde4/lib/QtNetwork4.lib;debug;C:/kde4/lib/QtNetworkd4.lib
^^^^^^^^^
^^^^^^^^^
</code>
</syntaxhighlight>


The first <tt>optimized</tt> part is translated by cmake to optimized.lib so we have got the ''cannot open file 'optimized.lib' error.''
The first <tt>optimized</tt> part is translated by cmake to optimized.lib so we have got the ''cannot open file 'optimized.lib' error.''

Latest revision as of 15:17, 23 June 2013

Template:I18n/Language Navigation Bar (zh TW)

常見問題

These are KDE's FAQ for CMake, there is also a CMake FAQ in the main CMake wiki.

如何讓我最喜歡的編輯器支援 CMake 語法和縮排?

請閱讀CMake Wiki 的 CMake 編輯器支援章節。這裡說明如何設定 Emacs(XEmacs works too)、VIM、Kate、KWrite 和 KDevelop。

我需要在建構過程中產生一些檔案,我該怎麼做?

使用 ADD_CUSTOM_COMMAND()。在 CMake wiki 的如何在建構過程中生成原始碼檔案有解釋

我想在建構過程中建立一個稍後使用的可執行檔。我該怎麼做?

假設可執行檔叫 genembed。那麼使用 KDE4_ADD_EXECUTABLE(foo RUN_UNINSTALLED ${fooSources})來建立可執行檔。RUN_UNINSTALLED 選項非常重要,因為可執行檔必須從建構目錄執行,並會連結到建構目錄中的一些函式庫。為了達成這個目的,可執行檔透過 RPATH 設定和 shell 腳本包裝編譯,和執行檔的名稱一樣只是多了個「.sh」。這個 shell 腳本建立 LD_LIBRARY_PATH 並呼叫實際的執行檔。

依照上面說明的在 ADD_CUSTOM_COMMAND() 中使用這個 shell 腳本包裝。 您可以通過查詢 WRAPPER_SCRIPT 來找到名稱和確切的路徑。這裡有一個來自 kdelibs/kstyles/keramik/ 的完整例子:

# build the executable
kde4_add_executable(genembed RUN_UNINSTALLED ${genembed_SRCS})

# get the name of the generated wrapper script (which sets up LD_LIBRARY_PATH)
get_target_property(GENEMBED_EXECUTABLE genembed WRAPPER_SCRIPT)

# and the custom command
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/keramikrc.h
  COMMAND ${GENEMBED_EXECUTABLE} --file ${CMAKE_CURRENT_BINARY_DIR}/keramikPics.txt > \
  ${CMAKE_CURRENT_BINARY_DIR}/pixmaps.keramik
  DEPENDS genembed ${keramikPics}
)

如你所見 genembed 也做為相賴關係列出。這表示 CMake 知道它應該在執行這些規則之前建構 genembed 執行檔。

我不想設定 -DCMAKE_INSTALL_PREFIX 命令列參數。CMake 是否支援 KDEDIR 環境變數?

不。KDE 4 反對使用 $KDEDIR。

為什麼我會得到/usr/lib/qt4/include/QtCore/qstring.h:536: undefined reference to `QString::fromLatin1_helper(char const*, int)'之類的編譯錯誤?

如果你有舊版的 Qt 4 在 qt/lib 目錄,你必須刪除這些舊版(4.0.1)檔案。

我要怎麼讓 CMake 創建 noisy makefiles?我希望看到 make 過程執行的指令。

傳遞 VERBOSE 變數給 make,例如:

% make VERBOSE=1

% VERBOSE=1 make

更多細節請查看 CMake wiki:有沒有選項可以產生更多的'verbose'編譯?

產生的 Makefiles 中沒有 'make distclean' 標籤。我該如何才能清理包括 cache 檔案在內的所有檔案?

只需刪除建構目錄,或建構目錄裡的內容。

I've got fatal error LNK1104: cannot open file 'optimized.lib' under Windows/msvc (release with debug info build)

This is a problem with KDE's CMakeLists.txt and CMake 2.6.0 and 2.6.1, it will be fixed soon.

QT_*_LIBRARIES must not be used in your target_link_libraries() line of CMakeLists.txt. Use QT_*_LIBRARY instead. Otherwise the variable will look like this (example for QT_QTNETWORK_LIBRARY):

optimized;C:/kde4/lib/QtNetwork4.lib;debug;C:/kde4/lib/QtNetworkd4.lib
^^^^^^^^^

The first optimized part is translated by cmake to optimized.lib so we have got the cannot open file 'optimized.lib' error.