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.

- static keyword is used to define which function will not be exposed.

- Header file isn't necessary.

 

- 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

void hello ();

static void hidden();

 

Test.c

#include <stdio.h>

#include "Test.h"

void hello () { printf("Hello from LIB!\n"); }

static void hidden() { printf("I am hidden!\n" ); }

 

- 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.c

#include <stdio.h>

#include <Test.h>

int main() {

hello();

//hidden(); //static functions are not exposed.

return 0;

}