title: Is it possible to compile statically with gcc or g++ on Linux based systems?
body: <p>I am working on a project which I would like to be able to "ship" to other Linux based computers as a complete executable with no dependencies. (In order that I can copy just the 1 file to other systems, and then run that file on those systems.)</p>
  
  <p>In the windows world, I think static linking is done just by passing <code>-static</code> to the compiler, perhaps with some other options for specific libraries*, if you are using Visual Studio.</p>
  
  <p>*eg: Using SFML you also have to define SFML_STATIC for some reason?</p>
  
  <p>Is this possible using gcc / g++, and if so how? I tried searching for this but didn't manage to find anything. I have heard before that this may be a non-trivial task.</p>
  
  <p>Edits:</p>
  
  <p>BasileStarynkevitch suggested compiling with the flag <code>-static</code>.</p>
  
  <p>I don't know if this is what I want, but I wrote a test program to try it out:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main()
  {
      std::cout &lt;&lt; "Link statically please" &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p>And then compiled with:</p>
  
  <pre><code>g++ main.cpp -o a.out -static
  g++ main.cpp -o b.out
  </code></pre>
  
  <p>The results are:</p>
  
  <pre><code>-rwxr-xr-x  1  1653098  a.out
  -rwxr-xr-x  1     9167  b.out
  </code></pre>
  
  <p>So it looks like it might be working?</p>
  
  <p>TonyD suggested a method of checking:</p>
  
  <pre><code>ldd a.out 
  not a dynamic executable
  
  ldd b.out
  linux-vdso.so.1 =&gt;  (0x00007fff3d5ac000)
  libstdc++.so.6 =&gt; /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fce5e34a000)
  libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007fce5df85000)
  libm.so.6 =&gt; /lib/x86_64-linux-gnu/libm.so.6 (0x00007fce5dc7e000)
  /lib64/ld-linux-x86-64.so.2 (0x00007fce5e677000)
  libgcc_s.so.1 =&gt; /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fce5da67000)
  </code></pre>