静态库调用静态库
以下操作均在windows平台下;为3个工程,两个静态库工程static1和static2,static2调用static1;一个测试程序Test.
1.static1工程,为静态库工程;
a.cpp如下:
#include "StdAfx.h"
#include"a.h"
int sub(int a,int b)
{
return a-b;
}
a.h如下:
#ifndef URANUS_DENTRY
#define URANUS_DENTRY
extern "C"
{
int sub(int a,int b);
}
#endif
2.在static2工程中,并把a.h添加到该工程,a.lib拷贝到当前目录
c.cpp如下:
#include "StdAfx.h"
#include "b.h"
#include "a.h"
#pragma comment(lib,"a.lib")
int abcd(int a,int b) //static2调用static1
{
return sub(a,b);
}
c.h如下:
#ifndef URANUS_DENTRY
#define URANUS_DENTRY
extern "C"
{
int abcd(int a,int b);
}
#endif
3.在Test工程中,为控制台应用程序,并把b.h添加到该工程,b.lib拷贝到当前目录
Test.cpp如下:
#include "stdafx.h"
#include "b.h"
#pragma comment(lib,"b.lib")
int main(int argc, char* argv[])
{
//printf("Hello World!\n");
printf("100-10=%d",abcd(100,10));
return 0;
}
问题:
1.但是在Test工程中中编译报错:
Linking...
Test.obj : error LNK2001: unresolved external symbol _abcd
Debug/Test.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Test.exe - 2 error(s), 0 warning(s)
用Test工程只调用一个static1静态库没问题;而static2调用static1,Test工程再调用一个static2静态库就会报上述错误。
2.
静态库中有没有DLLMAIN函数,自己可以添加DLLMAIN函数吗
^_^首次写静态库 新手