Author Topic: How to solve the “error:undefined reference to 'xxx' ” although 'xxx' exists  (Read 3079 times)

Offline wanggaoteng

  • Multiple posting newcomer
  • *
  • Posts: 30
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.

« Last Edit: February 14, 2019, 01:28:25 pm by wanggaoteng »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline wanggaoteng

  • Multiple posting newcomer
  • *
  • Posts: 30
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
« Last Edit: February 14, 2019, 02:44:09 pm by wanggaoteng »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
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++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Add readline.c to the targets Release and Debug

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

Tim S.
« Last Edit: February 14, 2019, 03:10:11 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline wanggaoteng

  • Multiple posting newcomer
  • *
  • Posts: 30
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.