1

I have two projects:

  1. Project1: An ATL COM based project whose output is a .lib file (a static library)

  2. Project2: An MFC based GUI Application which links to the static library so that the functions in that can be used.\

Whereever required, the .h file of the corresponding file is included in project1.

Now the calls from Project2 to functions in Project1 are happenning fine until I have to use a function which takes CString as a parameter.

Whenever there is a call which has CString as parameter (which is implemented in Project1's code), a link error pops up which states that it is unable to link to the function.

When googled I found out that the implementation of CString in ATL and MFC frameworks is different. So the obvious solultion is to pass CString which is implemented for ATL from Project2 because Project1 is ATL based.

So, I am passing CAtlString from Project2 when I am calling the function. But it is giving me back the same link error and in the error it is passing MFC version of the CString eventhough I am passing a CAtlString.

Can anyone give me the solution please.

More specific details of the project, I am providing below:

  1. ATL project is a COM based ATL project which has many hundered classes and functions. The output of it has been set to a .lib file. If any solution links to that .lib file, it can access all the methods exposed in it.

  2. MFC Project is an SD (Single Document) one. To be more specific, if at all it makes a difference to you, MFC Application is for CPPUNIT (used for unit testing).

  3. IDE - Microsoft Visual Studio 2005 Version 8.0.50727.762 I don't know the versions of ATL and MFC (I don't know how to check it, actually. If you could be of help here as well)

  4. The link error

    error LNK2019: unresolved external symbol "public: __thiscall NamespaceInProject1::CClassInProject1::CClassInProject1(class ATL::CStringT > >)" (??0CClassInProject1@NamespaceInProject1@@QAE@V?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z) referenced in function "public: void __thiscall CClassInCPPUNITTester::TesterFunction_PTC01(void)" (?TesterFunction_PTC01@CTestsXPathParser@@QAEXXZ) ClassInCPPUNITTester.obj

    NamespaceInProject1 - Namespace underwhich the class is declared in the Project1 CClassInProject1 - A Class in Project1 whose functions I am testing
    CClassInCPPUNITTester - The class in Project2 from which I am calling the function of the class CClassInProject1 TesterFunction_PTC01(void) - The function in function of Project2 is called.

  5. I am able to call all the methods that do not take CString as argument perfectly. I have tested them and they work just fine. Problem only occurs when I have CString as argument.

Please help

I have tried many solutions which are presented in Stackoverflow previously. None of them helped.

Note: i am passing the CString by value and not by reference when calling. Its a call by value.

Marius Bancila
  • 16,053
  • 9
  • 49
  • 91
Bhagirath N Sai
  • 199
  • 4
  • 16
  • I know its a lengthy question but please bear through the length of it. – Bhagirath N Sai Feb 28 '14 at 08:44
  • When you use a string, don't they both use cstringt.h from the atlmfc include directory. Are you passing the CStrings by value or by reference? You can sometimes solve this sort of problem by passing them by reference. – cup Feb 28 '14 at 09:57
  • Its a pass by value. I cannor change the code in the project1. I only have access to the .lib file. As in, i have access but i cannot change the code. So I am bound to pass it by value – Bhagirath N Sai Feb 28 '14 at 11:10
  • Is the signature of the missing routine correct? What does depends say? If the routine is missing then the only solution is to put the missing routine in project2. – cup Feb 28 '14 at 11:18
  • When you expect that a library should resolve a symbol but you still get a linker error I suggest comparing the decorated symbols *character by character*. Sometimes you have some subtle difference like a different calling convention. This may be caused by a wrong prototype (#ifdef?). – harper Feb 28 '14 at 13:40
  • The function in the error is a constructor? Show more code (header and call sites) – manuell Feb 28 '14 at 16:07
  • What's in the header? It won't help any to pass a `CAtlString` to a function, if that function is declared to take `CString`. Use `CAtlString` everywhere - in the header, in the implementation, in the caller. Alternatively, configure both projects to use the same settings. – Igor Tandetnik Feb 28 '14 at 16:14
  • @manuell yes the call is to the constructor. Doesn't matter though. Even if its a function, if it takes a CString, that's it. Boom! it fails. Otherwise, it just works fine. – Bhagirath N Sai Mar 03 '14 at 04:03
  • @IgorTandetnik yes I have tried that and no using CAtlString everywhere also didn't work. Configuring both projects to use the same settings is something which even I am thinking. Though I tried to make them as much similar as possible, it not happening. Any specific setting that you would like me to look into. – Bhagirath N Sai Mar 03 '14 at 04:05
  • #harper calling conventions in both the projects are same. Its __cdecl. which #ifdef should I look into. Its a huge project and there are many #ifdefs – Bhagirath N Sai Mar 03 '14 at 04:07

0 Answers0