çSTD库不会出现在目标文件链接 [英] C std library don't appear to be linked in object file

查看:217
本文介绍了çSTD库不会出现在目标文件链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这样的程序与所用math.h函数罪和stdio.h中功能的printf

I am using a program like this with math.h function "sin" and stdio.h function"printf" used

#include <stdio.h>
#include <math.h>

int main ()
{

    int x = sin(14);
    printf("hello");
    return 0;
}

和由ephemient <一说href=\"http://stackoverflow.com/questions/1033898/why-do-you-have-to-link-the-math-library-in-c\">here这libc.so和libm.so(数学函数)应该与程序上与打印共享库选项-L的对象文件中使用,无挂了,不过当我运行otool(类似于objdump的)的libc.so或libm.so被打印出来。

And as stated by ephemient here that libc.so and libm.so (for math functions) should have been linked with the program , though when I run otool (similar to objdump) on the object file with the option "-L" that prints the shared libraries used, None of libc.so or libm.so are printed out

otool -L com_ex1.o

所以究竟是什么原因呢?我使用otool错了吗?或者这些库不应该出现的共享库?

so what is the reason for this ? Am I using otool wrong? or the those libraries shouldn't appear as shared libraries ?

推荐答案

动态库被链接到最终的可执行文件,不
对象文件,所以你应该运行(例如)

Dynamic libraries are linked to the final executable, not to the object files, so you should run (e.g.)

otool -L com_ex1

这应该显示类似


com_ex1:
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)

由于在OS X上,数学库是libSystem中的一部分:

because on OS X, the math library is part of libSystem:


$ ls -l /usr/lib/libm.dylib
lrwxr-xr-x  1 root  wheel  15  3 Jun 01:39 /usr/lib/libm.dylib@ -> libSystem.dylib

这篇关于çSTD库不会出现在目标文件链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆