I created a VC++ solution. The solution has several project:
- One static library project named "Common".
- Several other dll project that link the library project. I've checked the
"Common" in the project dependence dialog box. Also I've tried to add
reference to Common ("References... -> add new reference").

However, I always got the errors:

Error 13 error LNK2001: unresolved external symbol "public: virtual class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > __thiscall Param<class CEmpty<double> >::toStr(void)"
(?toStr@?$InParam@V?$CEmpty@N@@@@UAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) proc.obj

What I missed?

Thanks.

Re: LNK2001 error by Marcus

Marcus
Thu Apr 13 02:54:11 CDT 2006

Adding references is only useful for managed assemblies.

To use parts from your native .lib, use the .lib file as a linker input for
you other projects and set the project dependeny manually.

Marcus Heege
www.heege.net

"nick" <nick@discussions.microsoft.com> wrote in message
news:9D226C27-7F30-4C0A-A63A-BEEA7287A8F3@microsoft.com...
>I created a VC++ solution. The solution has several project:
> - One static library project named "Common".
> - Several other dll project that link the library project. I've checked
> the
> "Common" in the project dependence dialog box. Also I've tried to add
> reference to Common ("References... -> add new reference").
>
> However, I always got the errors:
>
> Error 13 error LNK2001: unresolved external symbol "public: virtual class
> std::basic_string<char,struct std::char_traits<char>,class
> std::allocator<char> > __thiscall Param<class CEmpty<double>
> >::toStr(void)"
> (?toStr@?$InParam@V?$CEmpty@N@@@@UAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
> proc.obj
>
> What I missed?
>
> Thanks.



Re: LNK2001 error by Ulrich

Ulrich
Thu Apr 13 03:42:38 CDT 2006

Marcus Heege wrote:
> Adding references is only useful for managed assemblies.
>
> To use parts from your native .lib, use the .lib file as a linker input
> for you other projects and set the project dependeny manually.

Just for your info, you don't have to explicitly list a library or DLL as
linker inputs if they are in the same workspace and marked as dependency of
the project that uses them. Neat feature, IMHO.

Uli


Re: LNK2001 error by Marcus

Marcus
Thu Apr 13 06:35:01 CDT 2006

"Ulrich Eckhardt" <eckhardt@satorlaser.com> wrote in message
news:eff1h3-vdm.ln1@satorlaser.homedns.org...
> Marcus Heege wrote:
>> Adding references is only useful for managed assemblies.
>>
>> To use parts from your native .lib, use the .lib file as a linker input
>> for you other projects and set the project dependeny manually.
>
> Just for your info, you don't have to explicitly list a library or DLL as
> linker inputs if they are in the same workspace and marked as dependency
> of
> the project that uses them. Neat feature, IMHO.
>
> Uli
>

Very nice feature. Indeed.



Re: LNK2001 error by Igor

Igor
Thu Apr 13 07:19:41 CDT 2006

"nick" <nick@discussions.microsoft.com> wrote in message
news:9D226C27-7F30-4C0A-A63A-BEEA7287A8F3@microsoft.com
> However, I always got the errors:
>
> Error 13 error LNK2001: unresolved external symbol "public: virtual
> class
> std::basic_string<char,struct std::char_traits<char>,class
> std::allocator<char> > __thiscall Param<class CEmpty<double>
> >::toStr(void)"
> (?toStr@?$InParam@V?$CEmpty@N@@@@UAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
> proc.obj

Have you by any chance implemented methods of a template class in a .cpp
file? That's not going to work. The compiler needs to see the
implementation at the point the template is used, so the code has to be
in .h file.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: LNK2001 error by nick

nick
Thu Apr 13 08:45:03 CDT 2006

Yes, I've implemented methods of template class in a .cpp file. Does it mean
we must use inline function for method of template classes?

"Igor Tandetnik" wrote:

>
> Have you by any chance implemented methods of a template class in a .cpp
> file? That's not going to work. The compiler needs to see the
> implementation at the point the template is used, so the code has to be
> in .h file.
> --
> With best wishes,
> Igor Tandetnik
>
> With sufficient thrust, pigs fly just fine. However, this is not
> necessarily a good idea. It is hard to be sure where they are going to
> land, and it could be dangerous sitting under them as they fly
> overhead. -- RFC 1925
>
>
>

Re: LNK2001 error by Abdo

Abdo
Thu Apr 13 10:25:04 CDT 2006

"nick" <nick@discussions.microsoft.com> wrote in message
news:F0AA0D78-3080-4807-8B12-EC134B1D2E26@microsoft.com...
> Yes, I've implemented methods of template class in a .cpp file. Does it
mean
> we must use inline function for method of template classes?
>


Not necessarily inline, but you have to include the implementation in the
header...

--
Abdo Haji-Ali
Programmer
In|Framez



Re: LNK2001 error by nick

nick
Thu Apr 13 11:09:01 CDT 2006

I've used the inline function and so I moved the definition of the method to
head file. However, I have new Link error?

Error 1 error LNK2005: "public: __thiscall std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >(char const *)"
(??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z)
already defined in common.lib(Common.obj) msvcprtd.lib



"Igor Tandetnik" wrote:

> "nick" <nick@discussions.microsoft.com> wrote in message
> news:9D226C27-7F30-4C0A-A63A-BEEA7287A8F3@microsoft.com
> > However, I always got the errors:
> >
> > Error 13 error LNK2001: unresolved external symbol "public: virtual
> > class
> > std::basic_string<char,struct std::char_traits<char>,class
> > std::allocator<char> > __thiscall Param<class CEmpty<double>
> > >::toStr(void)"
> > (?toStr@?$InParam@V?$CEmpty@N@@@@UAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
> > proc.obj
>
> Have you by any chance implemented methods of a template class in a .cpp
> file? That's not going to work. The compiler needs to see the
> implementation at the point the template is used, so the code has to be
> in .h file.
> --
> With best wishes,
> Igor Tandetnik
>
> With sufficient thrust, pigs fly just fine. However, this is not
> necessarily a good idea. It is hard to be sure where they are going to
> land, and it could be dangerous sitting under them as they fly
> overhead. -- RFC 1925
>
>
>

Re: LNK2001 error by Igor

Igor
Thu Apr 13 21:25:01 CDT 2006

"nick" <nick@discussions.microsoft.com> wrote in message
news:0EC4D8C2-CBFD-439E-9DB9-40CACC169AB9@microsoft.com
> I've used the inline function and so I moved the definition of the
> method to head file. However, I have new Link error?
>
> Error 1 error LNK2005: "public: __thiscall
> std::basic_string<char,struct std::char_traits<char>,class
> std::allocator<char> >::basic_string<char,struct
> std::char_traits<char>,class std::allocator<char> >(char const *)"
> (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z)
> already defined in common.lib(Common.obj) msvcprtd.lib

You are using a static library that is built against a different CRT
flavor than the rest of your application. Make sure all projects use
consistent compiler options.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925