CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Dec 2005
    Location
    SJCampos - SP - Brazil
    Posts
    30

    LINK error: LNK2020 - Should I link the unmanaged libraries <math.h>, <stdio.h> ?

    I am developing a Managed class that is a wrapper for other unmanaged classes that uses the old C++ libraries: <math.h>, <stdio.h>,<string.h>, <stdlib.h>.

    My little project compiles all right, but I get this LINK error:

    LNK2020: unresolved token (0A000019) ??_7type_info@@6B@
    I did not link this files (<math.h>, <stdio.h>,…). Do I need to do this? If I need, how I can do that?

    Thanks in advance.

  2. #2
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: LINK error: LNK2020 - Should I link the unmanaged libraries <math.h>, <stdio.h> ?

    If this appears you do not have RTTI enabled. Please do so in the Compiler Options in your project properties.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  3. #3
    Join Date
    Dec 2005
    Location
    SJCampos - SP - Brazil
    Posts
    30

    Smile Re: LINK error: LNK2020 - Should I link the unmanaged libraries <math.h>, <stdio.h> ?

    Thank you very much NoHero.
    I did what you said.

    I did not say before, I am developing a C++.Net Template. C++ Managed Wraaper to wrapp unmanaged code.


    I had lots of LNK2019 errors and then, I ´ve applied some instructions of Microsoft: http://www.support.microsoft.com/?sc...d=2990&sid=149. Now, most of these errors have gone. But I still have link errors. Like that:
    error LNK2019: unresolved external symbol _strupr and error LNK2019: unresolved external symbol _hypot. error LNK2001: unresolved external symbol _hypot .
    Why I get these errors? Why Microsoft C++ .NET 2003 could not link properly the standard libraries <math.h>, <string.h> ???

    Thanks a lot.

    Eliseu.

  4. #4
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: LINK error: LNK2020 - Should I link the unmanaged libraries <math.h>, <stdio.h> ?

    Then you forgot to link the libraries of the default C library inside your application.

    Project Properties -> Linker -> Input -> Additional Libraries -> And add msvcrt.lib for release version and msvcrtd.lib for debug version.

    These libraries may also have a version suffix. Like msvcrt80.lib or something like that. I am not quite sure though, better you look them up in your Visual Studion installation directory -> VCX (X is the version number you are using) -> Libs.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  5. #5
    Join Date
    Dec 2005
    Location
    SJCampos - SP - Brazil
    Posts
    30

    Red face Re: LINK error: LNK2020 - Should I link the unmanaged libraries <math.h>, <stdio.h> ?

    NoHero, I did what you wrote me. But the linking process stills having the same errors:


    Basicas.obj : error LNK2019: unresolved external symbol _strupr referenced in function "void __cdecl LatsGMSt2sGMS(char *,int &,int &,int &,double &)" (?LatsGMSt2sGMS@@YAXPADAAH11AAN@Z)

    Basicas.obj : error LNK2019: unresolved external symbol _hypot referenced in function "double __cdecl AnguloPP2(double,double,double,double)" (?AnguloPP2@@YANNNNN@Z)

    Tmgeod.obj : error LNK2001: unresolved external symbol _hypot
    I did not find other versions for msvcrtd.lib in VC7\lib. Just this.

    Interesting that I am using others funcions from <math.h>, <string.h>, <stdio.h> and <stdlib.h> and is ok on the linking. Do you have any idea about why some funcionts are linked and others not?

    Thanks for your help.

  6. #6
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: LINK error: LNK2020 - Should I link the unmanaged libraries <math.h>, <stdio.h> ?

    Firstly, which version of DevStudio are you using ? There are two now : 2003 and 2005, although it shouldn't really be a problem unless you're using the Beta for 2005. Even then this shouldn't happen, but this is to just narrow things down.

    Anyway, I'm including a VC++.NET (DevStudio 2003) project which does just what you're having problems with. It's a console application, created from the wizards.

    And the code is in the source folder in solution explorer, CodeGuruTemp1.cpp.

    I hope it helps.

    Darwen.
    Attached Files Attached Files
    Last edited by darwen; December 29th, 2005 at 05:48 PM.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  7. #7
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: LINK error: LNK2020 - Should I link the unmanaged libraries <math.h>, <stdio.h> ?

    All these functions above are within the Microsoft C Runtime, but not ANSI standard. Here is another resource on this C Runtime. Also be sure your source files using these functions are compiled as unmanaged.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  8. #8
    Join Date
    Dec 2005
    Location
    SJCampos - SP - Brazil
    Posts
    30

    Smile Re: LINK error: LNK2020 - Should I link the unmanaged libraries <math.h>, <stdio.h> ?

    Thanks Guys.

    I really apreciate your help. I am not on the office now. I will come back on MOnday and I will test your sugestion. Yes NOHero, I was looking this table of LIBs today but I did not have time to test them yet.

    By the way, I am using Visual Studio 2003.

    I wish a fantastic happy new year to U.

    Take care.
    Last edited by Eliseu_CEL; December 29th, 2005 at 09:00 PM. Reason: mistakes of English

  9. #9
    Join Date
    Dec 2005
    Location
    SJCampos - SP - Brazil
    Posts
    30

    Question Re: LINK error: LNK2020 - Use of MSVCP71.DLL

    NoHero, on that link there is this option

    MSVCRT.LIB Multithreaded, dynamic link (import library for MSVCR71.DLL). Be aware that if you use the Standard C++ Library, your program will need MSVCP71.DLL to run. /MD _MT, _DLL
    It says:
    your program will need MSVCP71.DLL to run.
    What does it means:
    Any application built with Visual C++ .NET using the /MD switch will necessarily use msvcr71.dll.
    Do I need to do something about MSVCP71.DLL??? Do I need to include this someway? I ´ve tried several options to include this but is not possible. Than I think it is enough to have this file on Visual Studio Libraries...

  10. #10
    Join Date
    Dec 2005
    Location
    SJCampos - SP - Brazil
    Posts
    30

    Question Re: LINK error: LNK2020 - Should I link the unmanaged libraries <math.h>, <stdio.h> ?

    Thanks for your help Darwen. Ive´run your project. It´s worked.

    I just do not understand why i needed to change strupr(x) to
    _strupr(x), or hypot for _hypot???

    Do you have a clue about this?

  11. #11
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: LINK error: LNK2020 - Should I link the unmanaged libraries <math.h>, <stdio.h> ?

    I just read your report and it was reporting errors for _hypot et al. Actually you can remove the underscore from the start and it still works fine.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  12. #12
    Join Date
    Dec 2005
    Location
    SJCampos - SP - Brazil
    Posts
    30

    Exclamation Re: LINK error: LNK2020 - Should I link the unmanaged libraries <math.h>, <stdio.h> ?

    But for my project i get link errors if I do not use _hypot _strupr. Just for these 2. For anothers functions, I do not need to use underscore.

    I ´ve put my project. See it in Basicas.cpp and TMGEOD.cpp these 2 functions.

    Thank U very much.
    Last edited by Eliseu_CEL; February 6th, 2006 at 04:12 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured