[英]Not able to compile C source files using make. CMake error Cannot find source files but they are there
[英]Is it possible to recompile some source files on make install using CMAKE
讓我解釋一下這個問題。 我有一個C代碼,其中C字符串中包含其他插件的搜索路徑。 只要程序停留在cmake的構建目錄中,字符串就應在構建目錄內包含plugin文件夾。 例如
char *plugindir = "/home/.../myproject/build/plugins:/usr/share/myproject/plugins";
如果該程序通過make install
我想將此字符串更改為
char *plugindir = "/usr/share/myproject/plugins";
並在安裝之前重新編譯/重新鏈接該程序。 使用CMAKE如何實現這種行為?
有很多解決方案,我可以告訴您有關2的信息:
使用配置文件,因此plugindir不會經過硬編碼,而是從配置文件中動態獲取。 這是更好的解決方案,但您可以找到。 這涉及到像這樣的一些庫的使用。
使用#指令。 這是一個更簡單的解決方案。 在源文件中,添加以下內容:
#ifdef DIST
char *plugindir = "/usr/share/myproject/plugins";
#else
char *plugindir = "/home/.../myproject/build/plugins:/usr/share/myproject/plugins";
#endif
而且,您可以使用DIST預處理程序變量(在C代碼或Makefile中)區分開發版本或“已安裝”代碼版本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.