title: Chain of C libraries into C++
body: <p>I have a very trivial problem including a chain of C libraries into a C++ main project. I've experience with C but it's the first time that I'm programming in C++.</p>
  
  <p>The structure of the project is a single folder with inside:</p>
  
  <ul>
  <li>main.cpp</li>
  <li>Mylib_1.c</li>
  <li>Mylib_1.h</li>
  <li>Mylib_2.c</li>
  <li>Mylib_2.h</li>
  </ul>
  
  <hr>
  
  <p>main calls -> Mylib_1.h that calls ->  My_lib2.h</p>
  
  <pre><code>//main.cpp
  #include "Mylib_1.h"
  
  //Mylib_1.h
  #include "Mylib_2.h"
  </code></pre>
  
  <hr>
  
  <p>main contains both Mylib_1 and Mylib_2 functions and typedef structs</p>
  
  <p>Mylib_1 uses typedef structs and functions of Mylib_2</p>
  
  <hr>
  
  <p>Everything inside each Mylib_x.h is wrapped between extern "C", like this:</p>
  
  <pre><code>#ifndef __MYLIB_X_H
  #define __MYLIB_X_H
  
  #ifdef __cplusplus
  extern "C" {
  #endif 
  
  mycode         
  
  #ifdef __cplusplus
  }
  #endif 
  
  #endif
  </code></pre>
  
  <hr>
  
  <p>But when I try to compile it with eclipse kepler on Ubuntu 12.04 x64, I get: </p>
  
  <blockquote>
    <p>Mylib_1.h error: Mylib_2_type_t does not name a type</p>
    
    <p>main.cpp  error: Mylib_2_function1 was not declared in this scope</p>
    
    <p>...</p>
  </blockquote>
  
  <p>Only the above sections are marked as error in eclipse, the header looks included fine.</p>
  
  <p>Furthermore according to eclipse, the __cplusplus flag is false into Mylib_2.h but true into Mylib_1.h</p>
  
  <p>Thinking of some eclipse error, I've tried to manually build the project via g++ (v4.6.3) but I got the same exact problem when I've tried to link the libraries .o with the main.cpp</p>
  
  <p>Seems stupid but I can't figure out what could it be. Any suggestion? </p>
  
  <p>Thank you</p>