From: wscholine on
I have some old C-style code that builds as C++. I'd like to start
using ATL utility classes in it. The projects are makefile-based, and
I've found something that puzzles me.

I want to use ATL::CString in particular, but when I created an
instance of a CString I got "error LNK2001: unresolved external symbol
"class ATL::CAtlStringMgr ATL::g_strmgr" "

atlstr.h does in fact mention an extern g_strmgr, and when I manually
add %VCINSTALLDIR%\atlmfc\lib\atls.lib to the linker command the error
goes away.

There's a #pragma comment(lib, "atls.lib") in atlbase.h, which is
supposed to cause the compiler to generate a linker dependency, but it
appears not to be working. I tried explicitly adding a /LIBPATH:
%VCINSTALLDIR%\atlmfc\lib to my linker command and it still does not
fly.

I have looked at a bunch of .vcproj projects that make heavy use of
ATL::CString, and I cannot find any explicit dependencies on that
library in them.

Is there some kind of dependency magic in the IDE that lets it
automatically figure out that it needs link the ATL libraries? Does
the IDE compiler process #pragma comment() differently than cl does?
From: Alex Blekhman on
"wscholine" wrote:
> Is there some kind of dependency magic in the IDE that lets it
> automatically figure out that it needs link the ATL libraries?
> Does the IDE compiler process #pragma comment() differently than
> cl does?

There is no magic. It shuld work. The IDE uses exactly the same
cl, there is no special compiler for IDE. I just tried to create
empty Win32 console project and added

#include <atlbase.h>
#include <atlstr.h>

in "stdafx.h" header after other includes. I can use `Cstring'
class without any problem. IDE just sets up include paths for the
compiler.


HTH
Alex