我正在使用 g ++(Ubuntu 7.4.0-1ubuntu1〜18.04)7.4.0
来学习 C ++我有以下代码:
#include <iostream>
void log(std::string message);
int main() {
log("HI");
}
#include <iostream>
void log(std::string message)
{
std::cout << message << std::endl;
}
编译并运行时,出现以下错误:
/tmp/ccYckYXk.o: In function `main':
main.cpp:(.text+0x43): undefined reference to `log(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: error: ld returned 1 exit status
请问代码有什么问题吗?