From: Ashutosh on
Hi,
I trying to build an application(http://www.naughter.com/smtp.html - it
uses OpenSSL) by statically linking the MFC. It builds fine if set to
use MFC in shared DLL ( I don't have a choice here. MFC must be
statically linked)

I get errors like these

Error 1 error LNK2005: _strncmp already defined in
libcmt.lib(strncmp.obj) MSVCRT.lib
Error 2 error LNK2005: __errno already defined in
libcmt.lib(dosmap.obj) MSVCRT.lib
Error 3 error LNK2005: _memmove already defined in
libcmt.lib(memmove.obj) MSVCRT.lib
Error 4 error LNK2005: _strchr already defined in
libcmt.lib(strchr.obj) MSVCRT.lib


Now, if I exclude libcmt.lib from linking, I get these errors

Error 1 error LNK2001: unresolved external symbol ___argv nafxcw.lib
Error 2 error LNK2001: unresolved external symbol ___argc nafxcw.lib


Any ideas how to build this?

Regards,
Ashutosh
From: John on
hi ,guy,
why do you must use mfc static option.
if you ignore libcmt.lib, you should use mfc in shared dll option.
or the compiler cant find it.
only a guess.
good wish.

"Ashutosh" wrote:

> Hi,
> I trying to build an application(http://www.naughter.com/smtp.html - it
> uses OpenSSL) by statically linking the MFC. It builds fine if set to
> use MFC in shared DLL ( I don't have a choice here. MFC must be
> statically linked)
>
> I get errors like these
>
> Error 1 error LNK2005: _strncmp already defined in
> libcmt.lib(strncmp.obj) MSVCRT.lib
> Error 2 error LNK2005: __errno already defined in
> libcmt.lib(dosmap.obj) MSVCRT.lib
> Error 3 error LNK2005: _memmove already defined in
> libcmt.lib(memmove.obj) MSVCRT.lib
> Error 4 error LNK2005: _strchr already defined in
> libcmt.lib(strchr.obj) MSVCRT.lib
>
>
> Now, if I exclude libcmt.lib from linking, I get these errors
>
> Error 1 error LNK2001: unresolved external symbol ___argv nafxcw.lib
> Error 2 error LNK2001: unresolved external symbol ___argc nafxcw.lib
>
>
> Any ideas how to build this?
>
> Regards,
> Ashutosh
>
From: David Ching on
"Ashutosh" <smbs-msdn(a)nospam.nospam> wrote in message
news:u1cmGtyzIHA.4492(a)TK2MSFTNGP02.phx.gbl...
> Hi,
> I trying to build an application(http://www.naughter.com/smtp.html - it
> uses OpenSSL) by statically linking the MFC. It builds fine if set to use
> MFC in shared DLL ( I don't have a choice here. MFC must be statically
> linked)
>
> I get errors like these
>
> Error 1 error LNK2005: _strncmp already defined in libcmt.lib(strncmp.obj)
> MSVCRT.lib Error 2 error LNK2005: __errno already defined in
> libcmt.lib(dosmap.obj) MSVCRT.lib Error 3 error LNK2005: _memmove already
> defined in libcmt.lib(memmove.obj) MSVCRT.lib Error 4 error LNK2005:
> _strchr already defined in libcmt.lib(strchr.obj) MSVCRT.lib
>
> Now, if I exclude libcmt.lib from linking, I get these errors
>
> Error 1 error LNK2001: unresolved external symbol ___argv nafxcw.lib Error
> 2 error LNK2001: unresolved external symbol ___argc nafxcw.lib
>
> Any ideas how to build this?
>

This may be related to:
A LNK2005 error occurs when the CRT library and MFC libraries are linked in
the wrong order in Visual C++

http://support.microsoft.com/default.aspx?scid=kb;en-us;148652

-- David


From: "Charles Wang [MSFT]" on
Hi Ashutosh,
I understand that you encountered the link error when you build the third
party library in statically link.
If I have misunderstood, please let me know.

From the error message, it is a common seen issue. You do not need to
exclude libcmt.lib from linking. I recommend that you check if all the
dependency projects or libraries are compiled with the same setting /MT[d].
Ensure that all of them have one setting here. You can find this setting at
Project Properties->Configuration Properties-> C/C++ -> Code Generation->
Runtime Library.

For more information, you may refer to this article:
Linking to MFC/CRT dynamically and statically in one image
http://blogs.msdn.com/nikolad/archive/2005/01/28/362778.aspx

Hope this helps. If you have any other questions or concerns, please feel
free to let me know.

Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: msdnmg(a)microsoft.com.
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================

From: Ashutosh on
Hi,
Thanks all for your help/comments! :)

I library that I have to link with my project doesn't have a project
file. It uses makefiles(its very complex)

Can you please tell me where to change the settings for linking MFC
statically. Actually, I don't think that this library is using MFC
(99.99% sure).

I checked the options for 'cl.exe' and 'link.exe' but found no options
for that.

the flags being used for cl are

/MD /Ox /O2 /Ob2 /W3 /WX /Gs0 /GF /Gy /nologo -I"C:\Program
Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include"
-DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32
-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE
-DOPENSSL_USE_APPLINK -I. /Fdout32dll -DOPENSSL_NO_CAMELLIA
-DOPENSSL_NO_SEED -DOPENSSL_NO_RC5 -DOPENSSL_NO_MDC2 -DOPENSSL_NO_TLSEXT
-DOPENSSL_NO_CMS -DOPENSSL_NO_KRB5 -DOPENSSL_NO_DYNAMIC_ENGINE


and for linker it's

/nologo /subsystem:console /opt:ref /LIBPATH:"C:\Program Files\Microsoft
Visual Studio 8\VC\PlatformSDK\Lib"

If this library/dll is not using MFC then what needs to be done so that
it doesn't create any problem when used in another project which links
MFC statically?


Regards,
Ashutosh

Charles Wang [MSFT] wrote:
> Hi Ashutosh,
> I understand that you encountered the link error when you build the third
> party library in statically link.
> If I have misunderstood, please let me know.
>
> From the error message, it is a common seen issue. You do not need to
> exclude libcmt.lib from linking. I recommend that you check if all the
> dependency projects or libraries are compiled with the same setting /MT[d].
> Ensure that all of them have one setting here. You can find this setting at
> Project Properties->Configuration Properties-> C/C++ -> Code Generation->
> Runtime Library.
>
> For more information, you may refer to this article:
> Linking to MFC/CRT dynamically and statically in one image
> http://blogs.msdn.com/nikolad/archive/2005/01/28/362778.aspx
>
> Hope this helps. If you have any other questions or concerns, please feel
> free to let me know.
>
> Best regards,
> Charles Wang
> Microsoft Online Community Support
> ===========================================================
> Delighting our customers is our #1 priority. We welcome your
> comments and suggestions about how we can improve the
> support we provide to you. Please feel free to let my manager
> know what you think of the level of service provided. You can
> send feedback directly to my manager at: msdnmg(a)microsoft.com.
> ===========================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
>
> Note: The MSDN Managed Newsgroup support offering is for
> non-urgent issues where an initial response from the community
> or a Microsoft Support Engineer within 1 business day is acceptable.
> Please note that each follow up response may take approximately
> 2 business days as the support professional working with you may
> need further investigation to reach the most efficient resolution.
> The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by
> contacting Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ============================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
> =========================================================
>