如何在Ubuntu Linux下编译C?

前端之家收集整理的这篇文章主要介绍了如何在Ubuntu Linux下编译C?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我将下面的代码a previous question剪切并粘贴到一个名为“avishay.cpp”的文件中,然后运行
gcc avishay.cpp

只能从链接获取以下错误消息。出了什么问题,我该怎么办?

carl@carl-ubuntu:~/Projects/StackOverflow$ gcc -static avishay.cpp 
/tmp/cccRNW34.o: In function `__static_initialization_and_destruction_0(int,int)':
avishay.cpp:(.text+0x41): undefined reference to `std::ios_base::Init::Init()'
avishay.cpp:(.text+0x46): undefined reference to `std::ios_base::Init::~Init()'
/tmp/cccRNW34.o: In function `A::func()':
avishay.cpp:(.text._ZN1A4funcEv[A::func()]+0x11): undefined reference to `std::cout'
avishay.cpp:(.text._ZN1A4funcEv[A::func()]+0x16): undefined reference to `std::basic_ostream<char,std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,std::char_traits<char> >&,char const*)'
avishay.cpp:(.text._ZN1A4funcEv[A::func()]+0x1e): undefined reference to `std::basic_ostream<char,std::char_traits<char> >& std::endl<char,std::char_traits<char> >(std::basic_ostream<char,std::char_traits<char> >&)'
avishay.cpp:(.text._ZN1A4funcEv[A::func()]+0x26): undefined reference to `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> >&))'
avishay.cpp:(.text._ZN1A4funcEv[A::func()]+0x36): undefined reference to `std::cout'
avishay.cpp:(.text._ZN1A4funcEv[A::func()]+0x3b): undefined reference to `std::basic_ostream<char,std::char_traits<char> >::operator<<(int)'
/tmp/cccRNW34.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

C代码(不是我的代码,我只是试图运行它):

#include <iostream>
using namespace std;

class A
{
private:
   int _dmember;

public:
   void func()
   {
     cout<<"Inside A!! "<<endl;
     cout<<_dmember; // crash when reach here.
   }
};

int main ()

{

    A* a= NULL;

    a->func(); // prints "Inside A!!!" 

    return 1;
}
你应该使用g而不是gcc来编译C程序。

对于这个特定的程序,我刚刚输入

make avishay

让我们弄清楚其余的。给你的可执行文件一个不错的名字,而不是a.out。

猜你在找的Ubuntu相关文章