Im having problems with this program.
I get this only error [Linker error] undefined reference to `Monomio::Monomio(int const&, unsigned int const&)' (that is Monomio's constructor) in Main.cpp. The problem is that i always have that error, no matter what the code is.
Im trying to descompose my program in parts, but i don't really know how what im doing wrong. I hope someone can lend me a hand
(by the way.. The code of the methods is correct, and everything is under the same folder )
EDIT : (Bazzy) What do you mean by linking the two sourcefiles?. Do you mean, creating Monomio.o from Monomio.hpp and Monomio.cpp ?
Somehow i got it working, using Dev C++ 's projects. It autogenerates a makefile . I can use all of Monomio's methods. However, I can't use the operator << with monomios on main.cpp (and i had already overloaded that operator)
1 2 3 4 5 6 7
int main (void)
{
Monomio a(3,2);
cout << a;
return 0;
}
the error i have is [Linker error] undefined reference to `operator<<(std::ostream&, Monomio const&)'
How are you compiling these? Are you compiling from command line?
You should compile with something like gcc monomio.cpp main.cpp -Wall -pedantic -lstdc++ -o monomio.exe or g++ monomio.cpp main.cpp -Wall -pedantic -o monomio.exe...
Im afraid im compiling using Dev C++ , so i don't use any command lines.
(this might sound ultra noob but i don't know how to get g++ on my windows console )
maybe its that what makes this not work.
Maybe i should use a custom makefile.. i don't know what to do
You have to make sure g++ (dev-c++ is an IDE) is compiling both files; if you only compile main.cpp then monomio.cpp doesn't exist.
You need to create monomio.o and main.o and then link them with ld. GCC/G++ should do that automagically.
(this might sound ultra noob but i don't know how to get g++ on my windows console )
You have to change your PATH variable; open regedit and go to hkey_local_machine\system\currentcontrolset\control\session manager\environment\ and open the REG_EXPAND or REG_SZ called "PATH". Add "location_of_g++" to the end. Obviously replace "location_of_g++" with the actual location, e.g. "C:\ProgramFiles\g++". That will configure command prompt to search in that folder for executables. Alternatively you could just put g++.exe and all of the other programs it needs (as.exe and ld.exe for example) in the system32 folder.
Take care not to do anything else to your path variable, such as delete things from it or cmd won't work properly (for example if you have nmap port scanner and you removed "%PROGRAMFILES%\nmap" then you wouldn't be able to use nmap from commmand line anymore). Moving g++ to system32 is probably the better idea. Make sure you copy gcc, g++, as, ld and any other dependant programs to the folder too, or gcc and g++ won't work. They will identify you when you try to run them if there are any broken dependancies though; for example, gcc might print "Installation error, cannot find ld" or something. I forget what the actual error message is.