谷动谷力

 找回密码
 立即注册

【Linux应用开发】fork()函数详解

查看数: 2077 | 评论数: 1 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2023-8-14 21:13

正文摘要:

本帖最后由 sunsili 于 2023-8-14 23:00 编辑 【Linux应用开发】fork()函数详解 1.fork()简介 函数原型: pid_t fork(void);//pid_t为int类型,进行了重载 pid_t getpid();// 获取当前进程的 pid 值。 pid_t ...

回复

sunsili 发表于 2023-8-14 21:36:04
本帖最后由 sunsili 于 2023-8-14 21:37 编辑

编译时遇到了错误:
gcc -o fork_test.a fork_test.c
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
分析要链接动态库
用命令:
gcc -shared -g -o fork_test.a fork_test.c
/usr/bin/ld: /tmp/cc1wgtVD.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/tmp/cc1wgtVD.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
但又出现问题, 按提示要加参数 fPIC的, 但我没用
重新用原始命令编译:
gcc -o fork_test.a fork_test.c
又OK了

+10

QQ|Archiver|手机版|深圳市光明谷科技有限公司|光明谷商城|Sunshine Silicon Corpporation ( 粤ICP备14060730号|Sitemap

GMT+8, 2024-5-26 15:20 , Processed in 0.110220 second(s), 46 queries .

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表