Hi everyone, I seem to be experiencing some problem with the linking of header files. I'm sort of creating Date structures and I have the following files:

  • Date.h: Class Date declaration
  • Date.cpp: Class Date functions definitions and auxiliary functions
  • DateFormat.h: Class DateFormat declaration (used to format Date objects)
  • DateFormat.cpp: Class DateFormat functions definitions and auxiliary functions
  • BadDate.h: Class BadDate declaration (used to throw exceptions)

Within my main programm I include Date.h, it is compiling well but the linker will give me this error: main_test.cpp||undefined reference to `Date::Date()'. It seems like it can't find the constructors definition within Date.cpp. When I combine the files into one big file above my main function everythin works great. :/

Recommended Answers

All 2 Replies

The issue is not with the header files, per se, but with the object files that the compiler produces before linking. You need to have the compiled object files linked together in the final version of the program, which (depending on how you are doing things) means having them together on the command line, or in a Makefile, or (most likely) in a project file of some sort. Just how you would proceed will depend on which compiler and/or IDE you're using.

I think I get it ;)
thanks for the reply

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.