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

  • SEARCH
  • Home
  • 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 8787323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:51:49+00:00 2026-06-13T21:51:49+00:00

I am new to Linux OS. I am trying to compile a .c file

  • 0

I am new to Linux OS. I am trying to compile a .c file using a makefile. The math library has to be linked. My makefile looks like this:

CC=gcc
CFLAGS=-Wall -lm

all:client

.PHONY: clean
clean:
    rm *~ *.o client

When I run make, I get the following error:

"undefined reference to rint"

So it is not able to link the math library.

But when I compile explicitly using

gcc client.c -lm -o client

it successfully compiles.

So how should I change my makefile such that it works. I have already tried adding LDFLAGS=-lm. But I get the same error.

I should also add that when I run make, it expands to

gcc -Wall -lm client.c -o client

(notice that when I run gcc explicitly with -lm at the end, it works).

  • 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-06-13T21:51:50+00:00Added an answer on June 13, 2026 at 9:51 pm

    Your linker (ld) obviously doesn’t like the order in which make arranges the GCC arguments so you’ll have to change your Makefile a bit:

    CC=gcc
    CFLAGS=-Wall
    LDFLAGS=-lm
    
    .PHONY: all
    all: client
    
    .PHONY: clean
    clean:
        $(RM) *~ *.o client
    
    OBJECTS=client.o
    client: $(OBJECTS)
        $(CC) $(CFLAGS) $(OBJECTS) -o client $(LDFLAGS)
    

    In the line defining the client target change the order of $(LDFLAGS) as needed.

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

Sidebar

Related Questions

I'm trying to build a shared library using gcc 4.6 on Linux, which is
i am new in programming under linux and trying to get working this code:
So I am trying to compile the libssh2 library on linux, but when I
I am new to Linux and I am trying to compile some code that
I am trying to compile gcc version gcc4.3.2 using gcc version 4.1.2 20080704 (Red
I'm pretty new to linux and using external code from java. I'm trying to
I'm new to GNU/Linux (Lubuntu 11.10) and am trying to compile some C source
I am trying to implement some kind of new Linux task scheduler so I
I am trying to build a script (I'm pretty new to linux scripting) and
I'm very new to Linux and programming on Linux. I'm trying to install OpenAL

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.