架构的未定义符号x86_64:我应该使用哪个架构? [英] Undefined symbols for architecture x86_64: Which architecture should I use?

查看:237
本文介绍了架构的未定义符号x86_64:我应该使用哪个架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在C ++中做一些非常简单的东西,但我找不到任何有关如何解决这个问题的信息。甚至我刚才说的只是编译和运行程序的书。

I'm trying to do some really simple stuff in C++, but I can't find any information on how to tackle this. Even the book I have just says "Just compile and run the program".

test.cpp

#include <iostream> 
using namespace std;

int main() 
{ 
    cout << "Never fear, C++ is here!"; 
    return 0;
}

编译器说:

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

code> -arch i386 和 -m32 ,但它总是说这是错误的架构。我应该使用哪一个?

I tried compiling with flags like -arch i386 and -m32 but it always says it's the wrong architecture. Which one should I use?

我在Mac上做这个,但是不使用XCode,只是gcc。

I'm doing this on a Mac but not using XCode, just gcc.

推荐答案

错误的结构并不是错误的,因为 std :: cout

The error isn't that it's the wrong architecture, it's that std::cout (and other symbols) isn't defined.

您应该编译并链接到 g ++ 不是 gcc ,以自动链接到正确的C ++库。

You should compile and link with g++ not gcc, to automatically link with correct C++ libraries.

这篇关于架构的未定义符号x86_64:我应该使用哪个架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆