简体   繁体   English

Windows 中出现“找不到标识符”错误,但 Mac 中没有

[英]“identifier not found” error in Windows but not in Mac

I have this function that works fine in my mac when when I try to compile my program in Windows I get an error:当我尝试在 Windows 中编译我的程序时,我有这个 function 在我的 Mac 上工作正常,我收到一个错误:

std::string myMainWindow::getPlansPath() {
    char cwd[1024];
    if (getcwd(cwd, sizeof(cwd)) != NULL) {
        printf("Current working dir: %s\n", cwd);
    } else {
        perror("getcwd() error");
    }

    std::string path = std::string(cwd) + std::string("/myfolder");

    return path;
}

Error:错误:

C:\path\to\project\gui\myMainWindow.cxx(876): error C3861: 'getcwd': identifier not found
ninja: build stopped: subcommand failed.

What can it be?会是什么?

UPDATE:更新:

I end up using QDir::currentPath() which was exactly what I wanted.我最终使用了QDir::currentPath()这正是我想要的。

getcwd is an UNIX specific function, it does not exist in Windows, the fact that it belongs to the <unistd.h> library is a good hint to that. getcwd是一个 UNIX 特定的 function,它在 Windows 中不存在,它属于<unistd.h>库的事实是一个很好的提示。 A possible solution would be to use _getcwd though I'm not familiar with it's use, I gather by the MSDN page, it's more or less the same.一个可能的解决方案是使用_getcwd虽然我不熟悉它的用途,我从 MSDN 页面收集到,它或多或少是相同的。

You'll have to use _getcwd or _wgetcwd in the <direct.h> or <wchar.h> headers on Windows .您必须在Windows<direct.h><wchar.h>标头中使用_getcwd_wgetcwd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM