Sometimes the code compiles fine, but there is still a message because the program needs some function or library that it can’t find. This is known as a link-time error.

As our program gets bigger, it is good practice to divide the program into separate files. After compiling them, the linker takes those separate object files and combines them into a single executable file. Link-time errors are found by the linker when it is trying to combine object files into an executable file.

Some common link-time errors:

  • Using a function that was never defined (more on this later)
  • Writing Main() instead of main()

Here’s an example of a link-time error message:


These errors are more hard to find, but remember, Google is your friend! Here, a good Google search would be: “C++ undefined reference to main”.



Try compiling to find the link-time error in sum.cpp.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?