Thread: incompatible implicit declaration of built-in function

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    41

    incompatible implicit declaration of built-in function

    warning: incompatible implicit declaration of built-in function âstrlenâ
    warning: undefined reference to `sqrt'
    warning: implicit declaration of function âstrcmpâ
    warning: implicit declaration of function âstrcatâ
    warning: incompatible implicit declaration of built-in function âstrcatâ

    I have all the necessary includes, do i need to do some extra command to get this to compile properly?

    How do i fix that when my SSH Secure Shell compiles the file, i get a bunch of those..

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Oonej
    I have all the necessary includes
    I'll believe it when I see it.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well you would need to post your code to back up your assertion that you're including all the right files.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    41
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <math.h>

    can't post code, as this is a class project and students in my class view them... not looking to get a F for "cheating" lol

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    41
    btw - this compiles fine and works 100% in my DevC++ IDE, but doesn't compile on the SSH server, do i need to amend the header files in the compile on the SSH or something?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You're missing <string.h> for strlen, strcmp and strcat.

    Also, to solve "undefined reference to `sqrt'" you may need to explicitly link to the math library, e.g., with -lm
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    41
    too many arguments for format /tmp/cc3hMW6h.o: In function [function name]

    what does that refer to?

    and also how do i amend the math.h file with -lm? never used it before

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Oonej
    too many arguments for format /tmp/cc3hMW6h.o: In function [function name]

    what does that refer to?
    My guess is that you used too many arguments for format

    Perhaps this has something to do with printf. Or maybe with a function call. I'm not sure because you provided so little information that only someone who has come across that error message before and remembers the context and solution is likely to be able to accurately tell you the problem and solution.

    Quote Originally Posted by Oonej
    and also how do i amend the math.h file with -lm? never used it before
    What compiler are you using? Are you compiling on the command line, or from an IDE?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Jun 2011
    Posts
    41
    SSH Secure Shell - command line

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Oonej
    SSH Secure Shell - command line
    SSH Secure Shell is not a compiler

    Let's suppose you are using gcc. Currently, you might be running:
    Code:
    gcc -o program source.c
    If my guess is correct, it may become:
    Code:
    gcc -o program -lm source.c
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Never modify header files like math.h present on the system.
    Besides -lm is a linker directive specified on the command line.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 06-19-2010, 07:42 AM
  2. Implicit Declaration Of Function
    By nathanpc in forum C Programming
    Replies: 1
    Last Post: 01-26-2010, 08:46 PM
  3. Replies: 2
    Last Post: 11-08-2007, 02:33 AM
  4. implicit declaration of function?
    By BoneXXX in forum C Programming
    Replies: 2
    Last Post: 04-27-2007, 11:04 PM
  5. Implicit declaration of function
    By soothsayer in forum C Programming
    Replies: 5
    Last Post: 02-28-2006, 02:56 PM