User forums > Using Code::Blocks
undefined reference
spartan:
I have delete previus topic because I came across few things. Again these are my files and their content
add.h:
#ifndef ADD_H_INCLUDED
#define ADD_H_INCLUDED
int add(int x, int y);
#endif // ADD_H_INCLUDED
add.cpp:
#include <iostream>
int add(int x, int y)
{
return x+y;
}
main. cpp:
#include <iostream>
#include "add.h"
using namespace std;
int main()
{
cout << "We add 3 and 5: " << add(3,5);
return 0;
}
Error is:
in line of main() cout << ... : undefined reference to 'add(int,int)' error: Id returned 1 exit status(I don't know if it's surely Id with I(big i) or l(lowercase L)).
I finally managed to get project manager on screen. My project is called exercise and here is structure of it in project manager:Sources(add.cpp, main.cpp), Headers(add.h), Others(). If anyone has any idea where bug lies pleas help me, I have to start my project as soon as possible.
EDIT: full build log
-------------- Build: Debug in exercise (compiler: GNU GCC Compiler)---------------
g++ -o bin/Debug/exercise obj/Debug/main.o
obj/Debug/main.o: In function `main':
/home/user/Namizje/CodeblocksProjects/exercise/main.cpp:7: undefined reference to `add(int, int)'
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
2 error(s), 0 warning(s) (0 minute(s), 0 second(s))
stahta01:
Post a [full] build log or stop wasting time on this website!
Edit2: The below is a hyperlink click on it and follow the directions!!
http://wiki.codeblocks.org/index.php/FAQ-Compiling_(errors)#Q:_How_do_I_troubleshoot_a_compiler_problem.3F
Edit3: Use rebuild instead of build! and post the full rebuild log or I will put you on my list of people not worth trying to help.
Tim S.
stahta01:
Still waiting for the full build log!
spartan:
Followed your link, everything is already set as it should be.Thanks for help!!
EDIT: here is (I sincerely hope it's full this time) build log
-------------- Clean: Debug in exercise (compiler: GNU GCC Compiler)---------------
Cleaned "exercise - Debug"
-------------- Build: Debug in exercise (compiler: GNU GCC Compiler)---------------
g++ -Wall -fexceptions -g -std=c++14 -c /home/user/Namizje/CodeblocksProjects/exercise/main.cpp -o obj/Debug/main.o
g++ -o bin/Debug/exercise obj/Debug/main.o
obj/Debug/main.o: In function `main':
/home/user/Namizje/CodeblocksProjects/exercise/main.cpp:7: undefined reference to `add(int, int)'
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 4 second(s))
2 error(s), 0 warning(s) (0 minute(s), 4 second(s))
stahta01:
Add the other source file to the project!
Build -> Rebuild gives me this as the full rebuild log.
--- Code: ----------------- Clean: Debug in exercise (compiler: GNU GCC Compiler)---------------
Cleaned "exercise - Debug"
-------------- Build: Debug in exercise (compiler: GNU GCC Compiler)---------------
i686-w64-mingw32-g++.exe -Wall -fexceptions -g -c C:\Users\stahta01\devel\open_source_code\no_version_control\Test\exercise\add.cpp -o obj\Debug\add.o
i686-w64-mingw32-g++.exe -Wall -fexceptions -g -c C:\Users\stahta01\devel\open_source_code\no_version_control\Test\exercise\main.cpp -o obj\Debug\main.o
i686-w64-mingw32-g++.exe -o bin\Debug\exercise.exe obj\Debug\add.o obj\Debug\main.o
Output file is bin\Debug\exercise.exe with size 1.69 MB
Process terminated with status 0 (0 minute(s), 14 second(s))
0 error(s), 0 warning(s) (0 minute(s), 14 second(s))
--- End code ---
Tim S.
Navigation
[0] Message Index
[#] Next page
Go to full version