无法向前声明以在C ++中工作

时间:2019-05-01 20:15:30

标签: c++ g++

我正在使用 g ++(Ubuntu 7.4.0-1ubuntu1〜18.04)7.4.0

来学习 C ++

我有以下代码:

  • main.cpp:
#include <iostream>

void log(std::string message);

int main() {
    log("HI");
}
  • log.cpp:
#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

请问代码有什么问题吗?

0 个答案:

没有答案