在编译apue相关代码期间链接的问题

时间:2016-09-05 16:08:23

标签: c ld

我正在尝试编译与“UNIX®环境中的高级编程”一书相关的代码

当我尝试编译这样的测试文件时:

$ gcc -L ../lib/ -l apue foo.c

我明白了:

/tmp/cccXkUae.o: In function `main':
foo.c:(.text+0x2b): undefined reference to `err_sys'
...
collect2: error: ld returned 1 exit status

但是,似乎函数是在lib ...

中定义的
$ grep err_sys ../lib/libapue.a 
Binary file ../lib/libapue.a matches

最终,这确实编译没有错误:

$ gcc foo.c ../lib/error.c

试图了解我做错了什么。

2 个答案:

答案 0 :(得分:1)

可用的源代码 在convert an unsigned integer into hexadecimal representationunsigned int中的apue.h标题include/libapue.a中的lib标题为gcc -I $apue_root/include -L $apue_root/lib your_file.c -lapue 。因此,要编译和链接libapue,您需要:

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

    if row == 0 {FIRDatabase.database().reference().childByAutoId().setValue("A")}

    if row == 1 {FIRDatabase.database().reference().childByAutoId().setValue("B")}
}

答案 1 :(得分:0)

如果要链接静态库(例如linux上的*.a文件),那么你可以像这样编译你的程序:

gcc foo.c ../lib/libapue.a

如果要将其与动态(共享)库(例如Linux上的*.a文件)链接,那么您可以使用您建议的命令命令:

gcc -L../lib/ foo.c -lapue