Code::Blocks Forums

User forums => Help => Topic started by: Drakonaut on June 03, 2015, 09:51:46 pm

Title: Compiler error
Post by: Drakonaut on June 03, 2015, 09:51:46 pm
Hi, I'm facing a problem here.

I am running Code::Blocks version Code::Blocks 13.12 on Windows 7 HP
(version OperatingSystemVersionNumber). The compiler I use is TDM-GCC
version 4.7.1.

Description of problem.
My project files fail to compile. Googling tells me that the problem seems to lie with the header file. I followed the steps by un-checking both "Compile" and "Link" boxes but the code gives me this error instead. I deleted all .gch files from the folder too.

Build log:
Code
mingw32-g++.exe  -o bin\Debug\C9E4.exe obj\Debug\main.o obj\Debug\namespace.o   
obj\Debug\main.o: In function `main':
C:/Users/Drakonaut/Desktop/Chapter 9 Ex1/C9E4/main.cpp:11: undefined reference to `SALES::setSales(SALES::Sales&, double const*, int)'
C:/Users/Drakonaut/Desktop/Chapter 9 Ex1/C9E4/main.cpp:12: undefined reference to `SALES::setSales(SALES::Sales&)'
C:/Users/Drakonaut/Desktop/Chapter 9 Ex1/C9E4/main.cpp:13: undefined reference to `SALES::showSales(SALES::Sales const&)'
C:/Users/Drakonaut/Desktop/Chapter 9 Ex1/C9E4/main.cpp:14: undefined reference to `SALES::showSales(SALES::Sales const&)'
collect2.exe: error: ld returned 1 exit status

I read some threads on this forum and some faced the same problem as me. I've got my main.cpp and namespace.cpp linked and compiled. However, it doesn't seem to solve the problem.
Oh, there are these "C9E4.depend" and "C9E4.layout". But I think it isn't related to the problem.
I cut out the "bin" and "obj" and let the compiler re-compile, but the problem is still there.

Thanks!
Title: Re: Compiler error
Post by: oBFusCATed on June 03, 2015, 10:22:48 pm
Have you read the link I've pasted you in the other topic?
Do you have definitions (body) for the functions that the linker is reporting as undefined?
Title: Re: Compiler error
Post by: Drakonaut on June 04, 2015, 03:57:19 am
Yes, I've read that but it doesn't solve my problem (Q: My build fails with multiple undefined reference errors?).

So I thought I would look at the error and realise that my functions are in the SALES namespace, but I had forgotten to put them in the curly braces.

Thanks for your help though!  :)