链接 c 和 c++ 对象文件
Link c and c++ object files
当我尝试链接c ++和c对象文件时,我收到链接器错误。它无法解析 c 对象文件中的符号。
这是我的控制台输出:
Undefined symbols for architecture x86_64:
"PF_OpenFile(char*)", referenced from:
snapshot::processItem(workItem) in snapshot.o
raid01::raid01(int) in raid01.o
raid01::execute_workItem(workItem) in raid01.o
"PF_AllocPage(int, int*, char**)", referenced from:
snapshot::processItem(workItem) in snapshot.o
raid01::raid01(int) in raid01.o
"PF_CloseFile(int)", referenced from:
snapshot::processItem(workItem) in snapshot.o
raid01::raid01(int) in raid01.o
raid01::execute_workItem(workItem) in raid01.o
"PF_UnfixPage(int, int, int)", referenced from:
snapshot::processItem(workItem) in snapshot.o
raid01::raid01(int) in raid01.o
raid01::execute_workItem(workItem) in raid01.o
"PF_CreateFile(char*)", referenced from:
snapshot::snapshot(char*) in snapshot.o
raid01::raid01(int) in raid01.o
"PF_GetThisPage(int, int, char**)", referenced from:
snapshot::processItem(workItem) in snapshot.o
raid01::execute_workItem(workItem) in raid01.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
下面是 c 对象文件上nm
的输出:
0000000000001730 s EH_frame0
0000000000001226 s L_.str
0000000000001242 s L_.str1
00000000000012a8 s L_.str10
00000000000012c5 s L_.str11
00000000000012ed s L_.str12
00000000000012f8 s L_.str13
000000000000131a s L_.str14
000000000000133b s L_.str15
000000000000135f s L_.str16
0000000000001384 s L_.str17
0000000000001398 s L_.str18
00000000000013aa s L_.str19
000000000000125d s L_.str2
00000000000013ba s L_.str20
00000000000013d2 s L_.str21
00000000000013de s L_.str22
00000000000013f0 s L_.str23
0000000000001405 s L_.str24
0000000000001430 s L_.str25
000000000000144b s L_.str26
000000000000127a s L_.str3
000000000000127d s L_.str4
0000000000001281 s L_.str5
0000000000001283 s L_.str6
0000000000001285 s L_.str7
000000000000128e s L_.str8
0000000000001298 s L_.str9
0000000000000c70 T _PF_AllocPage
0000000000001928 S _PF_AllocPage.eh
00000000000006a0 T _PF_CloseFile
0000000000001888 S _PF_CloseFile.eh
0000000000000260 T _PF_CreateFile
00000000000017c0 S _PF_CreateFile.eh
0000000000000370 T _PF_DestroyFile
00000000000017e8 S _PF_DestroyFile.eh
0000000000000e90 T _PF_DisposePage
0000000000001950 S _PF_DisposePage.eh
00000000000008e0 T _PF_GetFirstPage
00000000000018b0 S _PF_GetFirstPage.eh
0000000000000920 T _PF_GetNextPage
00000000000018d8 S _PF_GetNextPage.eh
0000000000000ae0 T _PF_GetThisPage
0000000000001900 S _PF_GetThisPage.eh
0000000000000200 T _PF_Init
0000000000001798 S _PF_Init.eh
0000000000000490 T _PF_OpenFile
0000000000001838 S _PF_OpenFile.eh
0000000000001120 T _PF_PrintError
00000000000019a0 S _PF_PrintError.eh
0000000000001050 T _PF_UnfixPage
0000000000001978 S _PF_UnfixPage.eh
U _PFbufAlloc
U _PFbufGet
U _PFbufReleaseFile
U _PFbufUnfix
U _PFbufUsed
00000000000019f0 S _PFerrno
0000000000001470 d _PFerrormsg
0000000000001a00 b _PFftab
00000000000011c0 t _PFftabFindFree
00000000000019c8 s _PFftabFindFree.eh
U _PFhashInit
0000000000000000 T _PFreadfcn
0000000000001748 S _PFreadfcn.eh
00000000000003f0 t _PFtabFindFname
0000000000001810 s _PFtabFindFname.eh
0000000000000100 T _PFwritefcn
0000000000001770 S _PFwritefcn.eh
U ___stderrp
U _close
U _exit
U _fprintf
U _free
U _lseek
U _malloc
U _open
U _perror
U _printf
U _read
0000000000000650 t _savestr
0000000000001860 s _savestr.eh
U _strcmp
U _strcpy
U _strlen
U _unlink
U _write
为什么相关符号以_
为前缀?这是导致问题的原因吗?
此外,C 文件是用 g++ 中的 -x c
编译的(如果相关,则为 dunno)。
听起来你需要
使C++例程与C联动兼容。参见:在C++源中,外部"C"的效果是什么?
相关文章:
- CMake-按正确顺序将项目与C运行时对象文件链接
- 如何在h文件中包含.o对象文件
- 停止cmake target_link_libraries将插件中静态库的两个对象文件链接到静态库本身
- 从对象文件(.o)在macos上制作归档文件(.a文件)
- 检测 COFF 对象文件中C++内联符号
- 特定对象文件的单线程生成
- 使用对象文件读取三角形数据网格
- 链接时,不同静态库中的同一对象文件
- 防止临时对象文件访问 MSVC 中的磁盘
- 对在不同二进制文件中创建的对象文件的依赖关系
- 内联函数的函数本地静态对象是否在共享对象文件之间共享?
- 是否有正确的方法对生成文件中的对象文件使用模板命令?(C++)
- ./main:加载共享库时出错:libopencv_highgui.so.4.0:无法打开共享对象文件:没有这样的文件或
- 使用 make 将对象文件放在特定目录中
- 如何从 3d 对象文件中获取 3d 坐标
- 为什么我的生成文件没有生成对象文件?
- 如何在OSX上正确创建C++对象文件(.o)
- sf::Windows上的音乐:api-ms-win-crt-locale-l1-1-0.dll:无法打开共享对象文件
- 使用nvcc(CUDA-RINSIDE)正确链接对象文件
- 链接节点本机模块中的提升库,对象文件需要替代库版本