简体   繁体   English

使用-std = c ++ 11作为编译器标志时在Linux上使用getpid

[英]getpid on linux while using -std=c++11 as compiler flag

I would like to use getpid function from headers sys/types.h, unistd.h (C style) when I am using -std=c++11 flag but after that I have : 我想在使用-std = c ++ 11标志时使用sys / types.h,unistd.h(C风格)标头中的getpid函数,但之后有:

"function getpid could not be resolved". “函数getpid无法解析”。

Is there is some kind of workaround or equivalent function? 有某种解决方法或等效功能吗?

@Edit: @编辑:

I check it one more time and it is not flag fault 我再检查一次,这不是标记错误

head.h head.h

#ifndef HEAD_H_
#define HEAD_H_

#include <sys/types.h>
#include <unistd.h>

void test();

#endif /* HEAD_H_ */

head.cpp head.cpp

#include "head.h"

void test()
{
    pid_t pid = getpid(); // Function 'getpid' could not be resolved
}

and this is weird because I also make test on "clean" project and there was no problem at all. 这很奇怪,因为我也在“干净”项目上进行了测试,根本没有问题。

main.cpp main.cpp中

#include <sys/types.h>
#include <unistd.h>

int main()
{
      pid_t pid = getpid();

      return 0;
}

It looks like I am not able to get any function from unistd, because 看来我无法从unisted获得任何功能,因为

    char* a_cwd = getcwd(NULL,0);

is also unresolved 还没有解决

#include <unistd.h>
#include <iostream>

int main()
{
  std::cout << getpid() << std::endl;
  return 0;
}

dgs@dhome:~/Develop/Test2$ g++ -std=c++11 getpid.cpp
dgs@dhome:~/Develop/Test2$ ./a.out
11980

dgs@dhome:~/Develop/Test2$ g++ --version
g++ (Debian 4.9.2-10) 4.9.2

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

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