Sign in to follow this  

Linking Error...

This topic is 3371 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, Basically my problem is a linking error. I get the following error: [I] [CODE] Compiler: Default compiler Building Makefile: "C:\Dev-Cpp\tests\Rotation\Makefile.win" Executing make... make.exe -f "C:\Dev-Cpp\tests\Rotation\Makefile.win" all g++.exe -c Rotation.cc -o Rotation.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" g++.exe Rotation.o Coord.o Vector.o -o "Rotation.exe" -L"C:/Dev-Cpp/lib" -mwindows -lglut32 -lglu32 -lopengl32 -lwinmm -lgdi32 Vector.o(.text+0x0):Vector.cc: multiple definition of `toDeg(float)' Rotation.o(.text+0x100):Rotation.cc: first defined here Vector.o(.text+0x28):Vector.cc: multiple definition of `toRad(float)' Rotation.o(.text+0x128):Rotation.cc: first defined here collect2: ld returned 1 exit status make.exe: *** [Rotation.exe] Error 1 Execution terminated [/CODE] [/I] Now, I had previously declared toDeg and toRad in my main. But I am trying to put that along with some other code into a Vector class. toDeg and toRad aren't actually part of the class - rather they are functions that are declared in the header file of the Vector class. Now, I have removed all traces of any kind of declaration for toDeg and toRad from anywhere but the Vector header, but I still get this error! I tried doing the rebuildAll to get rid of the old object files - but that didn't work. Obviously it doesn't know where these 'ghost' definitions are as it won't provide me with a line number... This is a super annoying error that I seem to be getting a lot. If anyone knows what's going on please help. I'm using Dev-C++. Ryan

Share this post


Link to post
Share on other sites
Yeah, i used to get a lot of those errors, it's really annoying.
Post the code for Vector and Rotation so i can see exactly where and how the functions are declared. The first thing that i can think of that would cause the problem is that you have the definition in the header file. That would mean that the function gets defined (and not just declared) in every .cpp (or .cc in your case) file that includes it. If that is the case then making the function inline should solve.

EDIT: looks like jyk beat me to it but my explanation is a lot simpler :D

Share this post


Link to post
Share on other sites
Thank you both! I didn't realize that the macro guard didn't ensure that you get only 1 instance... weird. Thank you so much, that's going to save me a lot of headaches! I got it working perfectly now :D

Ryan

PS
If you still want to see the code just ask and I'll post it.

Share this post


Link to post
Share on other sites
Quote:
Original post by csuguy
I didn't realize that the macro guard didn't ensure that you get only 1 instance

Yeah, i learned that the hard way too. The macro guard only stops a cpp file from including the same header twice, it doesn't protect against two cpp files from including the same header (which is only a problem if you have definitions in the header, which is not what a header is for).

Share this post


Link to post
Share on other sites
Quote:
Original post by XTAL256
(which is only a problem if you have definitions in the header, which is not what a header is for).

Except classes and templates.

Share this post


Link to post
Share on other sites

This topic is 3371 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this