Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: wanggaoteng on February 14, 2019, 01:04:00 pm

Title: How to solve the “error:undefined reference to 'xxx' ” although 'xxx' exists
Post by: wanggaoteng on February 14, 2019, 01:04:00 pm
Hi, there is an example in my textbook, it contains three files: main.c, readline.c and readline.h.
I build the project as picture 1 illustrated, and I'm sure no spelling mistake exists.
But when I compiling the project using codeblocks, an error appeared always: undefined reference to 'read_line', as the picture 0 illustrated.(readline.c contains the function definition of 'read_line()')
I checked the project carefully, I think no inappropriate exists (#include "readline.h" has added in main.c). When I move the function definition of read_line() to main.c, and compiling, then no error appeared.
How to fix this problem?
Best regards.

Title: Re: How to solve the “error:undefined reference to 'xxx' ” although 'xxx' exists
Post by: stahta01 on February 14, 2019, 02:00:52 pm
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F (http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F)

Make sure you are using an CB Project. If yes, post the full rebuild log.

Tim S.
Title: Re: How to solve the “error:undefined reference to 'xxx' ” although 'xxx' exists
Post by: wanggaoteng on February 14, 2019, 02:40:21 pm
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F (http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F)

Make sure you are using an CB Project. If yes, post the full rebuild log.

Tim S.
Hi, Tim,
I use the CB project, and the full rebuild log as the picture 2 illustrated.
I upload the whole project (test.rar) in the attachment.
Thank you.
P.S. My CB is codeblocks-17.12mingw-setup.exe
Title: Re: How to solve the “error:undefined reference to 'xxx' ” although 'xxx' exists
Post by: stahta01 on February 14, 2019, 03:02:47 pm
Post the full rebuild in code tags.
And, make sure the second file is part of the project.

Tim S.

Title: Re: How to solve the “error:undefined reference to 'xxx' ” although 'xxx' exists
Post by: stahta01 on February 14, 2019, 03:05:30 pm
Add readline.c to the targets Release and Debug

Edit:
Select readline.c file
File Properties
Tab: Build

Tim S.
Title: Re: How to solve the “error:undefined reference to 'xxx' ” although 'xxx' exists
Post by: wanggaoteng on February 15, 2019, 09:35:53 am
Add readline.c to the targets Release and Debug

Edit:
Select readline.c file
File Properties
Tab: Build

Tim S.
Thanks, Tim, the method works very well.
Best regards.