简体   繁体   中英

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 :

"function getpid could not be resolved".

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

#ifndef HEAD_H_
#define HEAD_H_

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

void test();

#endif /* HEAD_H_ */

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

#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

    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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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