我有src文章中的article.html測試libxml,我希望閱讀它的相對路徑'.article',但在clion中,cmake將當前目錄更改爲「/ home/roroco /.CLion12/system/cmake/generated/c9a7a4c5/c9a7a4c5/Debug0「,我的問題是:是否有get_current_source_dir()
?如何獲得c源代碼不cmake編譯目錄
更新這裏是我的ex.c:
#include <unistd.h>
#include "stdio.h"
int main(int argc, char **argv) {
puts(get_current_dir_name());
// /home/roroco/.CLion12/system/cmake/generated/b321980/b321980/Debug
FILE *f = fopen('article.html', "r");
fseek(f, 0, SEEK_END);
// Signal: SIGSEGV (Segmentation fault)
return (0);
};
這裏是我在這裏的文件樹
- ex.c
- CMakeLists.txt
- article.html
這似乎並非是一個C語言的問題,因此當你刪除C得到更好的反應標籤。請提供您嘗試實施的解決方案的一些示例。 – Erik
@Erik,這是關於C,我更新我的代碼 – nwaicaethi
非常好。 SIGSEGV發生是因爲你沒有檢查NULL的返回值''fopen'''。如果您使用絕對路徑而不是相對路徑,則會獲得更多成功。 – Erik