linux/windows:获取当前程序路径

windows

    char moduleFileName[MAX_PATH];
    GetModuleFileNameA(0, moduleFileName, MAX_PATH);

linux

char current_absolute_path[MAX_SIZE];
//获取当前程序绝对路径
int cnt = readlink("/proc/self/exe", current_absolute_path, MAX_SIZE);
if (cnt < 0 || cnt >= MAX_SIZE)
{
    
    
    printf("***Error***\n");
    exit(-1);
}

猜你喜欢

转载自blog.csdn.net/qq_29007291/article/details/119887667