Thread: Problem w/ codeblocks vs CPP (printf undefined reference)

  1. #1
    Registered User
    Join Date
    Mar 2019
    Posts
    50

    Problem w/ codeblocks vs CPP (printf undefined reference)

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    int main()
    {
        int a;
        int howMany;
        int maxAmmt = 25;
        printf("How many loops? (Max: 25)\n");
        scanf("%d", &howMany);
        for(a = 1; a <= maxAmmt; a++){
            printf("%d\n", a);    <<<-------------
            if(howMany == a){
                break;
            }
        }
        return 0;
    }
    
    on the gcc codeblocks Im getting this error saying undefined reference to printf, its the SAME code from CPP. When I google a bunch of answers say to used stdio.h. However, as you can see, I already included this. What do I need to do?

  2. #2
    Registered User
    Join Date
    Mar 2019
    Posts
    50
    nvm, had to relink mingw32 directory for compiler. Anybody know why I keep running into having to hit auto detect when I start up code blocks or I get a random error, or no compiler error? Its very weird, it shows the directory in global compiler settings > toolchain already. But then I hit auto detect, then everything runs fine???
    Last edited by Ctylersills; 03-20-2019 at 08:59 PM. Reason: typo

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You might have better luck posting about IDE specific problems on the Code Blocks community forum.
    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

  4. #4
    Registered User
    Join Date
    Mar 2019
    Posts
    50
    Thanks, not a big issue but would like to fix it. It’s a problem with my grandmothers computer that I use when I’m over there so I’ll do that next time I’m there.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    If you figure out which compilers are causing the issue; you can set a path in those compilers.
    I think I use C:/null to get rid of that message years ago. Where C: was a valid drive; but, null was an invalid path.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined reference to 'printf'
    By Marco Angelo in forum C++ Programming
    Replies: 1
    Last Post: 03-15-2016, 06:11 PM
  2. Undefined reference to 'Printf' ????
    By mwoelfel in forum C Programming
    Replies: 5
    Last Post: 04-27-2012, 01:42 PM
  3. problem with undefined reference
    By z9d in forum Windows Programming
    Replies: 2
    Last Post: 11-03-2010, 05:26 PM
  4. Undefined reference problem
    By Speedkill in forum C++ Programming
    Replies: 3
    Last Post: 09-30-2003, 01:42 PM
  5. Undefined Reference Problem
    By esilja in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2001, 09:05 AM

Tags for this Thread