title: How to link a C library with C++ application
body: <p>I am trying to use a library called <a href="https://www.tbi.univie.ac.at/RNA/ViennaRNA/doc/html/index.html" rel="nofollow noreferrer">libRNA</a>. I installed it following the instructions on their website. </p>
  
  <p>If I am calling functions of that library in a <code>main.c</code> file, I can compile it using the gcc compiler and it works like charm: </p>
  
  <pre><code> gcc -g -Wall -fopenmp -std=c++11 test.c -lRNA -lm -o test.out
  </code></pre>
  
  <p>But if we rename the file to <code>main.cpp</code> and compiling it with gcc</p>
  
  <pre><code>gcc -g -Wall -fopenmp -std=c++11 test.cpp -lRNA -lm -lstdc++ -o test.out
  </code></pre>
  
  <p>none of the referenced functions of the RNA lib can be found:</p>
  
  <pre><code>/home/joachim/tutorial_libs/test.cpp:18: undefined reference to `vrna_alloc(unsigned int)'
  /home/joachim/tutorial_libs/test.cpp:19: undefined reference to `vrna_alloc(unsigned int)'
  etc...
  </code></pre>
  
  <p>I read that gcc treats .cpp files as c++ files and .c files as c files. Does this mean I can not link the library with a c++ file? But how can it then be achieved to use the library within a c++ application? (needless to say that using g++ would not change the situation.)</p>
  
  <p>I am thankful for any hint or suggestion for additional reading! Thanks in advance!</p>