用gcc和-lm链接不上Ubuntu的定义CEIL() [英] Linking with gcc and -lm doesn't define ceil() on Ubuntu

查看:750
本文介绍了用gcc和-lm链接不上Ubuntu的定义CEIL()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用的GCC编译器,我需要使用<&math.h中GT;
问题是,它不能识别的库。
我也曾尝试 -lm 并没有什么。
我试图用这个函数是 CEIL(),我得到了以下错误:

 :未定义参考`CEIL
collect2:劳工处返回1退出状态

我使用的是最新的Ubuntu和math.h中是存在的。
我试图用 -lm 在不同的电脑,它完美地工作。

有谁知道如何解决这个问题?


我没有包括<&math.h中GT; 。另外,我使用的命令是:

 的gcc -o -lm FB file.c中


解决方案

把这个code和把它放在一个文件 ceil.c

 的#include<&math.h中GT;
#包括LT&;&stdio.h中GT;
INT主要(无效)
{
    的printf(%F \\ N,CEIL(1.2));
    返回0;
}

与编译:

  $ gcc的-o CEIL ceil.c
$ gcc的-o CEIL ceil.c -lm

一这两个应该工作。如果没有作品,显示每个编译完整的错误消息。需要注意的是 -lm (如果你编译源链接之前,对象或目标文件)出现在源文件名之后。

I am currently using gcc to compile and I need to use <math.h>. Problem is that it won't recognize the library. I have also tried -lm and nothing. The function I tried to use was ceil() and I get the following error:

: undefined reference to `ceil'
collect2: ld returned 1 exit status

I am using the latest Ubuntu and math.h is there. I tried to use -lm in a different computer and it work perfectly.

Does anyone know how to solve this problem?


I did include <math.h>. Also, the command I used was:

gcc -lm -o fb file.c

解决方案

Take this code and put it in a file ceil.c:

#include <math.h>
#include <stdio.h>
int main(void)
{
    printf("%f\n", ceil(1.2));
    return 0;
}

Compile it with:

$ gcc -o ceil ceil.c
$ gcc -o ceil ceil.c -lm

One of those two should work. If neither works, show the complete error message for each compilation. Note that -lm appears after the name of the source file (or the object file if you compile the source to object before linking).

这篇关于用gcc和-lm链接不上Ubuntu的定义CEIL()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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