Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6853687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:32:29+00:00 2026-05-27T01:32:29+00:00

I am currently using GCC to compile and I need to use <math.h> .

  • 0

I am currently using GCC to compile and I need to use <math.h>.
The 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 on a different computer, and it worked perfectly.

How can I solve this problem?

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

gcc -lm -o fb file.c
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:32:30+00:00Added an answer on May 27, 2026 at 1:32 am

    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).

    Notes:

    1. A modern compiler might well optimize the code to pass 2.0 directly to printf() without calling ceil() at all at runtime, so there’d be no need for the maths library at all.

    2. Rule of Thumb: list object files and source files on the command line before the libraries. This answer shows that in use: the -lm comes after the source file ceil.c. If you’re building with make etc, then you typically use ceil.o on the command line (along with other object files); normally, you should list all the object files before any of the libraries.

    There are occasionally exceptions to the rule of thumb, but they are rare and would be documented for the particular cases where the exception is expected/required. In the absence of explicit documentation to the contrary, apply the rule of thumb.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently using System.Web.UI.WebControls.FileUpload wrapped in our own control. We have licenses for Telerik. I
I am currently using Windows Server 2008 Standard and have several Hyper V machines.
I recently tried to use Qt Creator 1.3.2, Qt 4.6.2, and GCC 4.4.0 (32-bit
I'm working in a Linux environment with C++, using the GCC compiler. I'm currently
I need to compile my Qt application for Windows while I am using Fedora
I am currently using clock() function supplied by the time.h library. It gives me
On my computer I have Ubuntu 10.10 with gcc 4.4.4. I try to compile
I try to compile a erlang nif plugin on windows using the cygwin gcc.
I have a C++ eclipse project that I would like to easily compile In
I'm currently porting one of my projects to GCC, and I'm using the MinGW-w64

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.