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 7023513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:43:14+00:00 2026-05-27T23:43:14+00:00

When I compile the pared-down program below, I get the following error from the

  • 0

When I compile the pared-down program below, I get the following error from the linker:

$ gcc -std=c99 -O3 powltest.c -o powltest
/tmp/ccYkWTGI.o: In function `main':
powltest.c:(.text+0x7a): undefined reference to `powl'
collect2: ld returned 1 exit status

If I comment out the line with sscanf(), the compile is successful and the program runs correctly given the reduced functionality. It also works if I instead comment out the line containing powl()

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

int main(int argc, char *argv[])
{
    unsigned int bits = 5;
    unsigned int n = 0;
    unsigned long long start = 0;

    n = sscanf(argv[1], "%u", &bits);
    printf("%u\n", bits);
    start = powl(2, bits) - 1;
    printf("%llu\n", start);
}

Here are the versions:

$ gcc --version
gcc (Ubuntu 4.4.1-4ubuntu9) 4.4.1
$ ld --version
GNU ld (GNU Binutils for Ubuntu) 2.20

Same result on:

$ gcc --version
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-51)
$ ld --version
GNU ld version 2.17.50.0.6-14.el5 20061020

Runs:

$ ./powltest 42    # commented-out sscanf()
5
31
$ ./powltest 42    # commented-out powl()
42
0

What am I doing wrong?

  • 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-27T23:43:15+00:00Added an answer on May 27, 2026 at 11:43 pm

    When you comment out the sscanf call, all of the variables have values known at compile time, and the compiler’s optimiser is able to determine the result of the powl call without actually calling any functions declared in math.h.

    When you uncomment the scanf call, the optimiser is unable to determine at compile-time the result of the powl call, so it must call the real powl function, which is in a separate library that you must link in with your program with -lm.

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

Sidebar

Related Questions

When attempting to compile my C# project, I get the following error: 'C:\Documents and
Is it possible to compile and run OpenGL programs from under Cygwin? If yes,
VS2010 has supported the C++11 partially. I compile the code below in VS2010 RTM.
I have a problem in MSVC++ 2008 where VS2008 is throwing this compile error:
all! I'm trying to compile a program using PowerShell, but the command is being
I'm working on a pretty complex DSL that I want to compile down into
My current compile output is not being properly parsed in the compilation buffer. How
How do I compile, link and call different YACC grammars using yyparse() in one
I would like to compile a DLL under Visual Studio 2008 that depends on
When we compile a dll using __stdcall inside visual studio 2008 the compiled function

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.