开发者

error LNK2005: _sprintf already defined in ntdll.lib(ntdll.dll)

I'm linking against ntdll.lib to use ZwQueryInformationProcess and am using the Multi-threaded runtime library.

ntdll seems to define some of the crt functions. So, when I link against it and also use the runtime library, I get linker errors.

Can I force the linker to use the crt funct开发者_运维技巧ions and to ignore the ntdll symbols to get rid of the error? Or somehow else solve this error.

I know the documentation of ZwQueryInformationProcess suggests dynamic loading, but it's used in a static lib my main project is also linking to, and this has been working fine for a long time, so I'd prefer not to change it.

Thanks.

I've found a few discussions about this on other sites, eg: http://www.codeguru.com/forum/archive/index.php/t-414274.html but haven't seen anything that seems to provide a good solution. There are some mentions of changing the link order, but I can't see how to change the order in which the runtime library links via the project settings.


Changing the link order seems to solve it. To change the order of automatically linked libs, you need to ignore them by adding to "Ignore Specific Library" and then re-add them to "Additional Dependencies" in the order you want them linked. The error message was this:

1>libcmt.lib(wcstol.obj) : error LNK2005: _wcstoul already defined in ntdll.lib(ntdll.dll)

So, I added libcmt.lib as ignored, and also placed it at the start of the additional dependencies. This produced another error, which I followed with the same steps. So, the project properties ended up looking like this (ntdll.lib is at the end of the Additional Dependencies):

error LNK2005: _sprintf already defined in ntdll.lib(ntdll.dll)

I also found adding /verbose:lib to the Linker -> Command Line -> Additional Options to be useful so that you can see exactly which libs are being linked and in what order.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜