title: How to create a C++ library in Eclipse?
body: <p><a href="http://answers.yahoo.com/question/index?qid=20081112125751AApVBrX" rel="nofollow">Here</a> a person asks "How to make your own library in C++ ?". This is exactly the question that I have. There is an answer to this question:</p>
  
  <blockquote>
    <ol>
    <li>Create the files "mylibrary.h" and "mylibrary.cpp".</li>
    <li>Only compile the library, and it shouldn't have a "main()" function in
    it. This step will generate an object file called "myfile.o".</li>
    <li>Create another file called something like "main.cpp". In main.cpp
    you need to #include "mylibrary.h".</li>
    <li>Compile main.cpp and add the library from step 2 to link in (in this case "myfile.o"). If you don't add this library, you'll get a
    error message like "linker error - can't find function definition", or
    something like that.</li>
    </ol>
  </blockquote>
  
  <p>But I still have some questions:</p>
  
  <ol>
  <li>The Library.cpp should have a <code>main()</code> function. But what should be in this main function? I do not want my library to execute something by default, when my program starts. I want it to contain a set of functions that are executed only when they are called explicitly.</li>
  <li>In the step 4, it is written that I need to "Compile main.cpp and add the library from step 2", but I have already compiled the library on the step 2. Should I compile it one more time?</li>
  <li>What does "in this case 'myfile.o'" mean? What exactly should I do with "myfile.o" in this case?</li>
  <li>On the step 4 it is written "If you don't add this library, you'll get a error message". But what does "to add library" mean? On step 3 I put <code>#include "mylibrary.h"</code> into the main.cpp, so I have added the library? Or I need to do something more to add the library?</li>
  </ol>
  
  <p>Could you please help me to understand the answer?</p>
  
  <hr>
  
  <p><strong>ADDED:</strong> I think I need to use Eclipse to generate <code>.a</code>, <code>.lib</code>, <code>.so</code>, or <code>.dll</code> files? Does anyone know how I can do it and what exactly I should generate?</p>