Click to See Complete Forum and Search --> : linkage error


avi123
December 18th, 2003, 02:06 AM
Hello,

I have a COM dll, that I have created using ATL
I added to the project my own interface and class implementing it.
I have a VB client for this client abd everything is working just fine.

now I have a few libraries and I want to use thier functions inside my client.

I want one of my class/interface function to use one of this functions

but I'm not sure how am I supuse to do it, what I did I included the relevant h file and added a reference to the lib in my project

then when I created an instance of the class that is decleared in the lib I got the following likage errors:

MyProject 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> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in MyLib.lib(MyLib.obj)

and also this kind of error: (for all my functions in MyClass class defined in MyLib lib....)

MyProject error LNK2019: unresolved external symbol "public: __thiscall MyClass::~MyClass(void)" (??1CStockLevels@@QAE@XZ) referenced in function __unwindfunclet$??0MyLib@@QAE@XZ$0



I don't understand what is already defined and what am I suppouse to do to overcome it

Is there another way to add my Lib functionality into this project?

thanks
avi

darwen
December 18th, 2003, 03:53 AM
I've added libs without any problems. The same way you have.

All the linking libraries have to be the same throughout the project. You can't for instance, have a library linking to MFC dynamically and the main application project linking to it statically.

I would strongly suggest that this is the case with your first error. Some project is linking to the STL differently than every other project. Have a look at the settings.

Your second error : is the destructor for this class defined ? Is it in a .cpp which is part of the library ? Sounds like you haven't defined the destructor to me, and you've only just done a rebuild all which forced your old build out.

Darwen.

avi123
December 18th, 2003, 04:24 AM
thanks
about your first suggestion:
What setting should I change conserining the STL?
I mean where is it defined

about the second:
in one of the libs I don't have at all constructor & destructor and I still have the same errors...

Can you tell me step by step How did you link your static libs into your ATL project

Thanks

P.S I'm also getting this kinds of errors:

MyProject error LNK2005: ___xc_z already defined in MSVCRTD.lib(cinitexe.obj)


and :

MyProject warning LNK4006: "public: int __thiscall std::ios_base::width(int)" (?width@ios_base@std@@QAEHH@Z) already defined in MyLib.lib(MyLib.obj); second definition ignored

darwen
December 18th, 2003, 10:30 AM
Firstly :

Right click on each of your projects in the workspace and go to properties.

In the general tab make sure that the combo with 'statically linked MFC' etc in it is the same for all your projects.

I can't remember about STL but there may be another option there I think and make sure that all of these are the same too.

Secondly :

If you don't have a constructor or a destructor then that is your problem. Implement them and your second error will go away.

Thirdly :

Your last error is probably because of (1).

Darwen.

vicodin451
December 18th, 2003, 12:16 PM
Originally posted by darwen
I can't remember about STL but there may be another option there I think and make sure that all of these are the same too.

There is no "static library version" of the STL.

MyProject error LNK2005: ___xc_z already defined in MSVCRTD.lib(cinitexe.obj)

This sounds like, most likely, one or more static libraries were built to use one version of the CRT, and the COM DLL was build to use another.
Project Properties | C/C++ | Code Generation...