·  MVS 2008 – C++ – Create – LIB

 

- Info:

  - This tutorial shows how to use MVS 2008 and C++ to create static library.

  - It also shows how to create C++ Console Application which calls that LIB.

  - To use static library compiler needs to know where to find Test.h and linker where to find MyProject.lib.

 

- Create .lib:

  - Create C++ File Test.c

  - RC on MyProject – Properties... – Configuration Properties – General –

    Project Defaults – Configuration Type: Static Library (.lib) – OK

  - Debug – Start Without Debugging Ctrl+F5 (It should ask you to specify executable file)

 

    Test.h

    class Test {

    public:

      static void hello ();

             void hello2();

    private:

             void hidden();

    };

 

    Test.cpp

    #include <iostream>   //cout

    #include "Test.h"

    

    using namespace std;

    

    void Test::hello () { cout << "Hello from C++ LIB!"        << endl; }

    void Test::hello2() { cout << "Hello fom object function!" << endl; }

    void Test::hidden() { cout << "I am hidden!!"              << endl; }

 

- Create Test Application:

  - Create C++ Project MyProject2

  - Create C++ File Test.c

  - RC on MyProject2 – Properties – Configuration Properties – C/C++ – General –

    Additional Include Directories: D:\Installed\Programming\Workspaces\VisualStudio\Solutions\MySolution\MyProject       OK

    (Adds Compiler parameter: /I "D:\Installed\Programming\Workspaces\VisualStudio\Solutions\MySolution\MyProject")

  - RC on MyProject2 – References... – Add New Reference... – MyProject – OK – OK

    (Adds Linker parameter: "..\debug\myproject.lib")

  - Debug – Start Without Debugging Ctrl+F5

 

    Test.cpp

    #include <stdio.h>  

    #include <Test.h>

    

    int main() {

      Test::hello();

      Test test;

           test.hello2();

         //test.hidden(); //Can't access private members.

      return 0;

    }