【问题标题】:linux clone() function leads to weird compilation error, why?linux clone() 函数导致奇怪的编译错误,为什么?
【发布时间】:2017-05-24 22:34:12
【问题描述】:

我有一个简短的程序如下,我试图了解“克隆”功能的实际工作原理。

#include<stdio.h>
#include<sched.h>
#include<unistd.h>
#include<sys/types.h>
extern int errno;
int f(void*arg)
{
pid_t pid=getpid();
printf("child pid=%d\n",pid);
}
char buf[1024];
int main()
{
int ret=clone(f,buf,CLONE_VM|CLONE_VFORK,NULL);
if(ret==-1){
    printf("%d\n",errno);
    return 1;
}
printf("father pid=%d\n",getpid());
return 0;
}

g++4.1.2 编译它并说:

$g++ testClone.cpp
/usr/bin/ld: errno: TLS definition in /lib64/libc.so.6 section .tbss mismatches non-TLS reference in /tmp/ccihZbuv.o
/lib64/libc.so.6: could not read symbols: Bad value
collect2: ld returned 1 exit status

我也试过

g++ testClone.cpp -lpthread

也不编译。为什么?

【问题讨论】:

    标签: linux gcc compilation clone


    【解决方案1】:

    这与clone 无关,您对errno 的声明不正确。请改用#include &lt;errno.h&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-23
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多