OSX 编译 “Undefined symbols for architecture x86_64”错误的解决方法

在 OSX 下gcc编译C代码的时候出现一下错误

Undefined symbols for architecture x86_64:
“_res_9_init”, referenced from:
_switch_ns in connect-048ad1.o
_main in connect-048ad1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [connect] Error 1

Google 了半天都没有找到解决方法。后来找到一个偏方,gcc编译的时候加一个参数 -lresolv 即可


gcc  -lresolv  connect.c

VN:F [1.9.22_1171]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 2 votes)
OSX 编译 “Undefined symbols for architecture x86_64”错误的解决方法, 10.0 out of 10 based on 1 rating


电子邮件地址不会被公开。 必填项已用*标注