News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

How to solve the “error:undefined reference to 'xxx' ” although 'xxx' exists

Started by wanggaoteng, February 14, 2019, 01:04:00 PM

Previous topic - Next topic

wanggaoteng

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.


stahta01

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

wanggaoteng

Quote from: 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

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

stahta01

Post the full rebuild in code tags.
And, make sure the second file is part of the project.

Tim S.

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

stahta01

Add readline.c to the targets Release and Debug

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

Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

wanggaoteng

Quote from: 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.
Thanks, Tim, the method works very well.
Best regards.