Link Errors in VC.net that don't appear in VC 6.0 
Author Message
 Link Errors in VC.net that don't appear in VC 6.0

This problem has me stumped, and I am inclined to think it might be a problem with Visual Studio; however, if somebody can help me out, I'd really appreciate it:

1)  I successfully build a .DLL in VC6 containing one template class, Box<T>.  

2)  I then created a second .DLL project linked to this first, which contained two classes: Item, and Shop.  Item is a simple class to store information about any object, and Shop is a class containing as a data member a Box<Item> object.

3)  I created a simple console test application that links to both of the above DLLs, creates a Shop object, and runs through its methods as a test.

All of this compiles, links, and executes under Visual C++ 6.0.  However, when I bring the project into Visual C++.NET, I am getting a host of LNK2019 errors to the tune of:

Shop.obj: error LNK 2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Box<class Item>:::Box<class Item>(int)"

I am thinking that there is a problem with using template classes in DLLs under VC7, because this is not the first time i've run into this problem (in fact, this project was done as a simplification to pinpoint problems experienced elsewhere).  I know all the include and library paths are good, dependencies are setup, and everything is included where it should be.  Like I said, all this compiles under VC6, but breaks when imported (untouched) into VC7.

Any ideas?
-Jeremiah

**********************************************************************

Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...



Sat, 25 Dec 2004 22:37:55 GMT  
 Link Errors in VC.net that don't appear in VC 6.0
Hello Jeremiah,

I think Justin Michel can answer your question. He answered a similar post
before. For your convenience, I have included it here:

"It doesn't make any sense to export a template from a dll. You must export
an instantiation instead, but you probably don't want to do that either.
The only reason I can think of that you would definitely need to export a
template instantiation is if the instantiation is used as the base class
for another exported class. You can sidestep all these issues by keeping
all such code inline."

I hope this information is helpful.

Best regards,

Lion Shi, MCSE, MCSD
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.  2001 Microsoft Corporation. All rights
reserved.
--------------------

    Subject: Link Errors in VC.Net that don't appear in VC 6.0

    Newsgroups: microsoft.public.dotnet.languages.vc
    Date: Tue, 09 Jul 2002 07:37:55 -0700
    NNTP-Posting-Host: 66.129.71.26
    Lines: 1        
    Path: cpmsftngxa07!tkmsftngp01!tkmsftngp12
    Xref: cpmsftngxa07 microsoft.public.dotnet.languages.vc:11745
    X-Tomcat-NG: microsoft.public.dotnet.languages.vc

    This problem has me stumped, and I am inclined to think it might be a
problem with Visual Studio; however, if somebody can help me out, I'd
really appreciate it:

    1)  I successfully build a .DLL in VC6 containing one template class,
Box<T>.  

    2)  I then created a second .DLL project linked to this first, which
contained two classes: Item, and Shop.  Item is a simple class to store
information about any object, and Shop is a class containing as a data
member a Box<Item> object.

    3)  I created a simple console test application that links to both of
the above DLLs, creates a Shop object, and runs through its methods as a
test.

    All of this compiles, links, and executes under Visual C++ 6.0.  
However, when I bring the project into Visual C++.NET, I am getting a host
of LNK2019 errors to the tune of:

    Shop.obj: error LNK 2019: unresolved external symbol
"__declspec(dllimport) public: __thiscall Box<class Item>:::Box<class
Item>(int)"

    I am thinking that there is a problem with using template classes in
DLLs under VC7, because this is not the first time i've run into this
problem (in fact, this project was done as a simplification to pinpoint
problems experienced elsewhere).  I know all the include and library paths
are good, dependencies are setup, and everything is included where it
should be.  Like I said, all this compiles under VC6, but breaks when
imported (untouched) into VC7.

    Any ideas?
    -Jeremiah

    **********************************************************************

    Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...



Mon, 27 Dec 2004 11:32:50 GMT  
 Link Errors in VC.net that don't appear in VC 6.0
I agree that exporting templates from a DLL are not the best solution, but sometimes it is done regardless, esp. when working with 3rd parties who don't want to share source code.  The real question here is:

why does VC++ 6 compile my code, but not VC++ 7 (.NET)?

**********************************************************************

Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...



Mon, 27 Dec 2004 19:24:10 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VC 4.2 link error linking static libraries from VC 6.0

2. VC++6 convert to VC.Net link error

3. upgrade of dll from vc++ 6.0 to vc++.net

4. backward compatibility vc++ .net vc++ 6.0

5. vc 6.0 and vc .NET

6. Upgrading VC 6.0 custom appwizard application to VC .NET

7. VC 6.0 -> VC 5.0 Error

8. Error Compiling VC 6.0 program in VS.net B2

9. VC 6.0 Link error

10. Error while linking on VC 6.0

11. link error porting project file from old version to VC 6.0

12. Updating VC 6 program to VC .NET produces assertion error

 

 
Powered by phpBB® Forum Software