Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing only g++ works, but not "g++ -c" and ld
    text
    copied!<p>I have the following source code in main.cpp:</p> <pre><code>#include &lt;iostream&gt; #include &lt;iomanip&gt; int main() { std::cout &lt;&lt; "Hi" &lt;&lt; std::endl; return 0; } </code></pre> <p>Using this command works, and creates the executable file:</p> <pre><code>g++ -o main main.cpp </code></pre> <p>But this commands don't work:</p> <pre><code>g++ -c main.cpp ld -o main main.o </code></pre> <p>The second one errors with:</p> <pre><code>ld: warning: cannot find entry symbol _start; defaulting to 00000000004000e8 main.o: In function `main': main.cpp:(.text+0xa): undefined reference to `std::cout' main.cpp:(.text+0xf): 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*)' main.cpp:(.text+0x14): 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;)' main.cpp:(.text+0x1c): undefined reference to `std::ostream::operator&lt;&lt;(std::ostream&amp; (*)(std::ostream&amp;))' main.o: In function `__static_initialization_and_destruction_0(int, int)': main.cpp:(.text+0x4a): undefined reference to `std::ios_base::Init::Init()' main.cpp:(.text+0x4f): undefined reference to `std::ios_base::Init::~Init()' main.cpp:(.text+0x54): undefined reference to `__dso_handle' main.cpp:(.text+0x61): undefined reference to `__cxa_atexit' </code></pre>
 

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