Using your favorite tool editor, in my case vim, create two files with the next content:
teststaticlib.cpp
///
extern “C” int Test
{
return 123;
}
///
teststaticapp.cpp
///
#include <iostream>
extern “C” int Test();
int main()
{
std::cout << Test() << std::endl;
}
///
To build follow the next steps:
///
1) cl -c teststaticlib.cpp
///
( -c stands for “compiles without linking”)
///
2) lib teststaticlib.obj
///
And the final step is
///
3) cl teststaticapp.cpp teststaticlib.lib
///
Now you can try the exe file just generated.
Enjoy!
NOTE: To check an example using Visual Studio 2012 you may follow this link:
Static linking with Visual Studio