首页 新闻 会员 周边

静态库-关于__declspec(impexport)-疑问

0
[待解决问题]

静态库头文件(c语言):

1 #ifdef __cplusplus
2 extern "C" {
3 #endif 
4 
5 __declspec(dllexport) int __c(void);
6 
7 #ifdef __cplusplus
8 }
9 #endif

在c++代码中引用:

extern "C" __declspec(dllimport) int __c(void);
int
_tmain(int argc, _TCHAR* argv[]) { _tprintf(_T("%d....\n"), __c()); return 0; }

error LNK2019: 无法解析的外部符号 __imp___c,该符号在函数 main 中被引用

复制代码
extern "C" int __c(void);
int _tmain(int argc, _TCHAR* argv[])
{ 
    _tprintf(_T("%d....\n"), __c());
        return 0;
}
复制代码

去掉 __declspec(dllimport) 或者使用__declspec(dllexport)后就可以了。

静观海月的主页 静观海月 | 菜鸟二级 | 园豆:202
提问于:2018-01-17 12:43
< >
分享
所有回答(1)
0

因为静态库的头文件中没有定义__declspec(dllimport),参考 从static变量导出问题解析 __declspec(dllexport) 和 __declspec(dllimport)的作用

dudu | 园豆:30994 (高人七级) | 2018-01-17 15:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册