Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to compile C++ under Ubuntu Linux?
    primarykey
    data
    text
    <p>I cut&amp;pasted the below code from <a href="https://stackoverflow.com/questions/1696225/null-pointer-to-object-problems">a previous question</a> into a file called "avishay.cpp" and then ran </p> <pre><code>gcc avishay.cpp </code></pre> <p>only to get the following error messages from the linker. What went wrong, what should I have done?</p> <pre><code>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&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::operator&lt;&lt; &lt;std::char_traits&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, char const*)' avishay.cpp:(.text._ZN1A4funcEv[A::func()]+0x1e): undefined reference to `std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::endl&lt;char, std::char_traits&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;)' avishay.cpp:(.text._ZN1A4funcEv[A::func()]+0x26): undefined reference to `std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;::operator&lt;&lt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; (*)(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;))' 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&lt;char, std::char_traits&lt;char&gt; &gt;::operator&lt;&lt;(int)' /tmp/cccRNW34.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status </code></pre> <p>The C++ code (not my code, I was just trying to run it):</p> <pre><code>#include &lt;iostream&gt; using namespace std; class A { private: int _dmember; public: void func() { cout&lt;&lt;"Inside A!! "&lt;&lt;endl; cout&lt;&lt;_dmember; // crash when reach here. } }; int main () { A* a= NULL; a-&gt;func(); // prints "Inside A!!!" return 1; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload