Note that there are some explanatory texts on larger screens.

plurals
  1. POCompiling C++ code on Mac
    primarykey
    data
    text
    <p>I want to write very simple C++ programs on my Mac but I get errors. I don't have a lot of experience with C++ (and gcc) and the simple guides on the web also don't discuss this topic.</p> <p>Please have a look at my simple hello world program:</p> <pre><code>erik2:~[03:38 pm]$ cat hw.cpp #include &lt;iostream&gt; int main () { cout&lt;&lt;"Hello World!"; return 0; } erik2:~[03:38 pm]$ gcc hw.cpp hw.cpp: In function ‘int main()’: hw.cpp:5: error: ‘cout’ was not declared in this scope </code></pre> <p>Responding to the answers until now (thanks a lot), I put back(!) the namespace declaratation, but that doesn't result in a success, though:</p> <pre><code>erik2:~[03:51 pm]$ cat hw.cpp using namespace std; #include &lt;iostream&gt; int main () { cout&lt;&lt;"Hello World!"; return 0; } erik2:~[03:51 pm]$ gcc hw.cpp Undefined symbols: "___gxx_personality_v0", referenced from: ___gxx_personality_v0$non_lazy_ptr in ccphDFtO.o "std::ios_base::Init::~Init()", referenced from: ___tcf_0 in ccphDFtO.o "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*)", referenced from: _main in ccphDFtO.o "std::ios_base::Init::Init()", referenced from: __static_initialization_and_destruction_0(int, int)in ccphDFtO.o "std::cout", referenced from: __ZSt4cout$non_lazy_ptr in ccphDFtO.o ld: symbol(s) not found collect2: ld returned 1 exit status </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.
    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