Question:
C++ linker errors while writing a header file?
aswan k
2007-03-11 08:56:15 UTC
Im learning C++, and trying to write a header file called navtools.h which contains the declarations of some useful functions I have written. whenever i compile my "main.cpp", i get lots of errors like

" [Linker error] undefined reference to `CheckValidLat(float)' "

I tried copying another header file from functionx.com (just to see if it worked) and it also compiles with the same errors! can someone help me out?
Five answers:
2007-03-11 12:28:12 UTC
Here is what you need to do:



main.cpp:



...

#include "navtools.h"

...

CheckValidLat(5.4);

...



In the same folder as main.cpp, you put navtools.h. If you are compiling with MS Visual C++, make sure you add navtools.h to your project.



Remember that #include (and in general any #-directive) literally copies and pastes the referenced file into your .cpp file. So if you don't have the right #include, then it is as if you are using a function that you didn't declare anywhere.
Dan M
2007-03-11 10:38:40 UTC
Your main.cpp is calling a function CheckValidLat() that takes a float as an argument. The file containing CheckValidLat() needs to be compiled and linked with the main.cpp.



If CheckValidLat() function is already defined in main.cpp then check the data type of the argument being passed to it.
parodister
2007-03-11 10:11:37 UTC
Seems to me I had similar errors if I included the header file in the build without including the c++ file that had the actual implementation of the method. Try including the obj file from your compiled useful functions as input to the linker.
?
2016-10-02 02:44:43 UTC
see first you would be able to desire to renowned what's a linker and what's a linker errors. After code compilation, that code is proper with each and all the library applications existent on your turboC itemizing...Now, that's the interest of the linker to confirm the physique of the applications u have used like printf, scanf etc...Now you have used one function noted as "symbol_circle" which you have declared and noted as from the main function yet you havent declared the physique of it...for the time of linking time, the linker sees that the function is noted as in spite of the indisputable fact that it has have been given no corresponding code to execute...write a physique of that function.....then u will locate no linker errors will ensue..
Dont_wanna_display_it_!
2007-03-11 09:04:46 UTC
Hmm i do programm but not in c++ (YET lol) but here are some tips, is the the heder file in the same folder as the rest of the c++ files??? Might it be a syntax erorr??? In the the heder file are all the filenames right??? Well just keep tryin :).


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...