Author Topic: Error undefined reference  (Read 4219 times)

terry1

  • Guest
Error undefined reference
« on: July 14, 2019, 09:23:34 am »
OK, I was running version 16.01, and I liked it, everything worked out great. I have recently downloaded the newer version 17.12, now I am having major problems. For every program I create I use the following inline function:

inline void keep_window_open(){char ch; scanf("%s", ch);}

then right before the return 0; statement I would call the function this way:

keep_window_open();

This never failed, all my program compiled. However with this new release, I get the error : undefined reference to keep_window_open.

Even in the simplest of programs such as:

#include <stdio.h>
#include <stdlib.h>

inline void keep_window_open(){char ch; scanf("%s", ch);}

int main()
{
    printf("Hello world!\n");
    keep_window_open();
    return 0;
}

This will not compile, nothing will it use to in the older version, but now it won't

So what is up? I have my settings like they always were before, to use GNC GCC, I am using the console application template, just I like I always have before. So I do not understand why in this new version this won't work. Very frustrating.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1564
Re: Error undefined reference
« Reply #1 on: July 14, 2019, 11:14:13 am »
You don't need that trick to keep the window open, just check Project->Options->Build targets->Pause when execution ends.

If you want to use your method the line scanf("%s", ch) with ch defined as a char is incorrect, you should use %c.

For the compilation error please post a full rebuild patch, see:

http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

« Last Edit: July 14, 2019, 11:31:11 am by Miguel Gimenez »

Offline sodev

  • Regular
  • ***
  • Posts: 498
Re: Error undefined reference
« Reply #2 on: July 14, 2019, 10:08:27 pm »
This won't fix the undefined reference though. Apparently inline is quite tricky with C code, depending on the used standard the behavior is different, the newer CodeBlocks might ship a newer compiler that uses a different standard by default. The most easy fix would be to just remove the inline (im a C++ guy and don't know these little differences well).