Two projects are test1 and test2 respectively. Two Functions in test1 are called by test2. The usage is as follows:
// Test1.h
Intadd (intx, inty );
Intsubstract (intx, inty );
// Test1.cpp
# Include "test1.h"
Intadd (intx, inty)
{
Returnx + y;
}
Intsubstract (intx, inty)
{
Returnx-y;
}
Change the configuration type of test1 to static library. lib ).
// Test2.cpp
# Include <iostream>
// # Pragmacomment (lib, "test1.lib ")
# Include "D: \ User \ Documents \ VisualStudio2012 \ Projects \ test1 \ test1 \ test1.h" // Add the path test1.h. Otherwise, the header file cannot be found.
Usingnamespacestd;
Intmain ()
{
Cout <add (3, 4) <endl;
Cout <substract (5, 3) <endl;
Return0;
}
Set the project dependency of test2 to test1, right-click the test2 project, and add reference test1 for debugging.
This article is from the "cabbage" blog, please be sure to keep this source http://zhengyongkun.blog.51cto.com/1163218/1299828