Skip to content

macOS兼容性问题 #6

@ZZy979

Description

@ZZy979

当前的代码在Linux系统上可以编译通过,但是在macOS系统上会报错,每一章存在的问题如下:

第1章

问题1:getline函数与标准库<stdio.h>中的函数冲突

/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/stdio.h:355:9: error: 
      conflicting types for 'getline'
ssize_t getline(char ** __restrict __linep, size_t * __restrict __linecapp, FILE * ...

解决方法:在Makefile的CFLAGS变量后添加-D _ANSI_SOURCE

第2章

问题2:clang编译器不识别-Wno-builtin-declaration-mismatch选项

warning: unknown warning option '-Wno-builtin-declaration-mismatch'

解决方法:改为-Wno-incompatible-library-redeclaration

问题3:_test.out构建规则匹配错误

cc -o any_test.out any_test.o
Undefined symbols for architecture x86_64:
  "_any", referenced from:
      _main in any_test.o
ld: symbol(s) not found for architecture x86_64

解决方法:Makefile规则%_test.out放在%.out之前(在macOS上,一个目标匹配多个模式规则时,make并不是像文档10.5.4 How Patterns Match中所说选择匹配最准确的规则,而是选择第一个匹配的规则)

第3章

问题3

第4章

问题1、3

第5章

问题1、2、3,包括子目录

第6章

问题3

第7章

问题3

问题4:浮点计算规则差异导致以下单测失败

Testing rudimentary_calculator.out...9c9
<       -nan
---
>       nan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions