C - Undefined symbols for architecture x86_64 when compiling on Mac OSX Lion

浪尽此生 提交于 2019-11-30 18:19:59

The problem you encounter is in the linking stage, not compiling. You did not provide the implementation of GetString, only its declaration (through the .h file you #include).

To provide the implementation itself, you usually need to link against the library which includes it; this is usually done by the -l flag to g++. For example,

g++ file.cpp -lcs50

Your second sample code does link, because you manually (and explicitly) provide an implementation for GetString, though an empty one.

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