MAC OS X 10.8上的gcc 4.8抛出“架构x86_64的未定义符号: [英] gcc 4.8 on MAC OS X 10.8 throws "Undefined symbols for architecture x86_64: "

查看:267
本文介绍了MAC OS X 10.8上的gcc 4.8抛出“架构x86_64的未定义符号:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的mac os x 10.8中编写了这样的代码,当我使用gcc use_new.cpp -o use_new进行编译时,它会抛出如下错误消息:

 架构x86_64的未定义符号:
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>&)),引用自:
_main in ccr2vrRQ.o
std :: basic_ostream< char,std :: char_traits< char>> :: operator<(void const *),引用自:
_main in ccr2vrRQ.o
std :: basic_ostream< char,std :: char_traits< char>> :: operator<(double),引用自:
_main in ccr2vrRQ.o
std :: basic_ostream< char,std :: char_traits< char>> :: operator<(int),引用自:
_main in ccr2vrRQ.o
std :: basic_ostream< ; char,std :: char_traits _main in ccr2vrRQ.o
std :: ios_base :: Init :: Init(),引用自:$ b在ccr2vrRQ.o中$ b__static_initialization_and_destruction_0(int,int)
std :: ios_base :: Init ::〜Init(),引用自:
b $ bstd :: cout,引用自:
_main in ccr2vrRQ.o
std :: basic_ostream< char,std :: char_traits< char> >&安培; std :: endl< char,std :: char_traits< char> >(std :: basic_ostream< char,std :: char_traits< char>&&),引用自:
_main in ccr2vrRQ.o
std :: basic_ostream< char,std: :char_traits<炭> >&安培;的std ::运营商LT;< <的std :: char_traits<炭> >(std :: basic_ostream< char,std :: char_traits< char>&; char const *),引用自:
_main in ccr2vrRQ.o
operator delete(void * ),引用自:
_main in ccr2vrRQ.o
operator new(unsigned long),引用来自:
_main in ccr2vrRQ.o
ld:symbol(s)未找到架构x86_64
collect2:错误:ld返回1退出状态

当我使用g ++ use_new.cpp -o use_new是好的,谁可以帮助我!?谢谢!

  #include< iostream> 
struct fish
{
float weight;
int id;
int kind;
};
int main()
{
using namespace std;
int * pt = new int;
* pt = 1001;
cout<<int:<<< pt< <in location:<< pt<< endl;
double * pd = new double;
* pd = 100000001.0;
cout<<double:<<< pd<<"在位置:"<< pd<< endl;
cout<<int point pt is length<< sizeof(* pt)<< endl;
cout<<<<<<<<<<<<<<<<<<<<<<<<<<
delete pt;
删除pd;
cout<<(int *)你好吗?<< endl;
返回0;
}


解决方案

旧的4.2 GCC(我在设置我的非官方iOS工具链时遇到过这个问题)。 gcc 默认为C,并调用链接器而不链接到C ++标准库;相比之下, g ++ 默认使用C ++并且链接到C ++标准库。总而言之 - 可能的解决方案:

  gcc myprog.c -o myprog -lstdc ++ 

  g ++ myprog.c -o myprog 


all,I write a code like this in my mac os x 10.8,and when I use "gcc use_new.cpp -o use_new " to compile it,but it throws wrong message like this:

Undefined symbols for architecture x86_64:
  "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 ccr2vrRQ.o
  "std::basic_ostream<char, std::char_traits<char> >::operator<<(void const*)", referenced from:
      _main in ccr2vrRQ.o
  "std::basic_ostream<char, std::char_traits<char> >::operator<<(double)", referenced from:
      _main in ccr2vrRQ.o
  "std::basic_ostream<char, std::char_traits<char> >::operator<<(int)", referenced from:
      _main in ccr2vrRQ.o
  "std::basic_ostream<char, std::char_traits<char> >::operator<<(unsigned long)", referenced from:
      _main in ccr2vrRQ.o
  "std::ios_base::Init::Init()", referenced from:
      __static_initialization_and_destruction_0(int, int) in ccr2vrRQ.o
  "std::ios_base::Init::~Init()", referenced from:
      __static_initialization_and_destruction_0(int, int) in ccr2vrRQ.o
  "std::cout", referenced from:
      _main in ccr2vrRQ.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 ccr2vrRQ.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 ccr2vrRQ.o
  "operator delete(void*)", referenced from:
      _main in ccr2vrRQ.o
  "operator new(unsigned long)", referenced from:
      _main in ccr2vrRQ.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

and when I use "g++ use_new.cpp -o use_new" is OK,who can help me!? thank you!

#include <iostream>      
    struct fish              
    {
        float weight;
        int id;
        int kind;              
    };
    int main()               
    {
      using namespace std;   
      int* pt = new int;     
      *pt = 1001;            
      cout<<"int: "<<*pt<<"in location: "<<pt<<endl;
      double* pd = new double;
      *pd = 100000001.0;     
      cout<<"double: "<<*pd<<"in location: "<<pd<<endl;
      cout<<"int point pt is length "<<sizeof(*pt)<<endl;
      cout<<"double point pd is length "<<sizeof(*pd)<<endl;
      delete pt;             
      delete pd;             
      cout<<(int *)"How are you!"<<endl;
      return 0;
  }

解决方案

This is the case even with the old 4.2 GCC (I experienced this when I set up my unofficial iOS toolchain). gcc assumes C by default, and invokes the linker without linking to the C++ standard library; in contrast, g++ assumes C++ and links against the C++ standard library by default.

All in all - possible solutions:

gcc myprog.c -o myprog -lstdc++

or

g++ myprog.c -o myprog

这篇关于MAC OS X 10.8上的gcc 4.8抛出“架构x86_64的未定义符号:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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