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

混江龙づ霸主 提交于 2019-12-01 12:45:36

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)

Undefined references may happen when having many .c or .cpp sources and some of them is not compiled.

One good "step-by-step" explanation on how to do it is here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!