“undefined reference” error in a very very simple c++ program

后端 未结 2 1574
情深已故
情深已故 2021-01-16 11:47

I have a simple program, which I copied exactly from the example in http://www.learncpp.com/cpp-tutorial/19-header-files/ because I\'m learning how to make c++ programs with

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-16 12:22

    The code is almost perfect.

    Add a line #include "add.h" inadd.cpp`.

    Compile the files together as g++ main.cpp add.cpp and it will produce an executablea.out

    You can run the executable as ./a.out and it will produce the output "The sum of 3 and 4 is 7" (without the quotes)

提交回复
热议问题