1

好的,我在 Windows/Linux 共存一段时间后才切换到 MacOS。我打开一个简单的文本编辑器,编写一个简单的程序来检查一切是否正常。我知道还有其他关于此错误的线索,但似乎在所有其他情况下,问题都出在他们程序的特定部分,而这又比这复杂得多。我只是想理解为什么编译器会说出它所说的话,即使是这样一个简单的事情。

#include <iostream>
#include "numeri.h"
int main(void)

{

  std::cout << numeri() << std::endl;

  return 0;
}

//numeri.h

int numeri(void);

//numeri.cpp
#include "numeri.h"
int numeri(void)
{
  return (3);
}

我从 gcc helloworld.cpp -Wall 得到的是

Undefined symbols for architecture x86_64:
  "numeri()", referenced from:
      _main in cc6WY2MJ.o
  "std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))", referenced from:
      _main in cc6WY2MJ.o
  "std::basic_ostream<char, std::char_traits<char> >::operator<<(int)", referenced from:
      _main in cc6WY2MJ.o
  "std::ios_base::Init::Init()", referenced from:
      __static_initialization_and_destruction_0(int, int)in cc6WY2MJ.o
  "std::ios_base::Init::~Init()", referenced from:
      ___tcf_0 in cc6WY2MJ.o
  "std::cout", referenced from:
      _main in cc6WY2MJ.o
  "std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
      _main in cc6WY2MJ.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

2个案例:

1 - 我忘记了如何使用简单的标题(我作为前缀,我是一名物理专业的学生,​​我可以针对物理和数值模拟进行编程[或者至少,我可以],但我只是不太了解关于链接器编译器架构和这类东西)

2 - 出了点问题

4

1 回答 1

4

C++ 编译器是 g++, . 您还需要将 numeri.cpp 添加到命令行。

g++ helloworld.cpp numeri.cpp -Wall

于 2013-04-09T13:55:57.783 回答