C ++ Project编译为静态库,失败(链接器错误)为动态库.为什么? [英] C++ Project compiles as static lib, fails (linker error) as dynamic lib. why?

查看:359
本文介绍了C ++ Project编译为静态库,失败(链接器错误)为动态库.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VS2008本机C ++项目,希望将其编译为DLL.

I've a VS2008 native C++ project, that I wish to compile as a DLL.

它仅引用一个外部库(log4cplus.lib),并使用其功能. (自然也使用log4cplus的.h文件).

It only references one external library (log4cplus.lib), and uses its functions. (also uses log4cplus's .h files , naturally).

当我尝试将项目编译为静态库时,它成功了. 当我尝试作为DLL时,它失败了:

When I try to compile my project as a static library, it succeeeds. When I try as DLL, it fails :

1>MessageWriter.obj : error LNK2019: unresolved external symbol "public: static class log4cplus::Logger __cdecl log4cplus::Logger::getInstance(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &)" (?getInstance@Logger@log4cplus@@SA?AV12@ABV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z) referenced in function "class log4cplus::Logger __cdecl Log(void)" (?Log@@YA?AVLogger@log4cplus@@XZ)

与log4cplus.lib中的函数相关的其他错误有4个.

There are 4 more errors just like this related to functions within log4cplus.lib.

似乎有些愚蠢的东西..请帮助我:)

It seems like something really stupid.. please help me :)

谢谢!

我被链接到log4cplus.lib文件,并且发现它很好. 此外,log4cplus.lib具有100%的功能,我正在另一个项目中使用它,没有任何问题. 我的初衷是将我的项目编译为静态库,并在我正在编写的另一个DLL中使用它,但是这样做时,我在另一个项目中遇到了相同的链接器错误...

I am linked against the log4cplus.lib file, and it finds it just fine. also, the log4cplus.lib is 100% functional, I am using it in another project with no problems. My original intention was to compile my project as a static library and use it in another DLL I am writing, but when do this, I get the same linker errors in that other project...

编辑#2:

导致链接器错误的函数是静态函数..这可能是问题的一部分吗?

The functions which cause the linker errors are static functions.. could this be part of the problem?

推荐答案

wilx是正确的.我有相同的链接问题.

wilx is right.I have the same link problem.

我花了将近一天的时间解决这个问题.

it took me almost one day to slove this issue.

我已经下载了log4cplus-1.0.4,使用Visual Studio 2010打开该项目后,可以对其进行编译,无论是静态库还是动态库,都没有错误.

I have downloaded log4cplus-1.0.4, after I opened this project with visual studio 2010,compile it, both static and dynamic library, no error.

但是,当我尝试使用这些库时,无论是静态库还是动态库,都出现链接错误.

however, when I try to use those library, I got a link error,no matter static library or dynamic library.

原因是,默认情况下,这些项目使用多字节字符,但是,我自己的项目使用unicode,因此,要解决这些链接问题,只需更改一个项目的字符集即可.

the reason is,by default, those project use multi-byte character, however, my own project use unicode,so,to slove those link problem, you just need to change one project's charset.

两个unicode或两个多字节字符集.

both unicode or both multi-byte charset.

并在Visual Studio 2010中更改一个项目的字符集, 请参阅以下链接.

and to change one project's charset in visual studio 2010, see the following link.

如何在VC ++中关闭Unicode项目?

这篇关于C ++ Project编译为静态库,失败(链接器错误)为动态库.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆