我将下面的代码从
a previous question剪切并粘贴到一个名为“avishay.cpp”的文件中,然后运行
原文链接:https://www.f2er.com/ubuntu/349952.htmlgcc 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
#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; }