Click to See Complete Forum and Search --> : LINK error: LNK2020 - Should I link the unmanaged libraries <math.h>, <stdio.h> ?


Eliseu_CEL
December 27th, 2005, 01:42 PM
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.

NoHero
December 28th, 2005, 11:42 AM
If this appears you do not have RTTI enabled. Please do so in the Compiler Options in your project properties.

Eliseu_CEL
December 29th, 2005, 01:24 PM
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/?scid=kb;en-us;814472&spid=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.

NoHero
December 29th, 2005, 01:32 PM
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.

Eliseu_CEL
December 29th, 2005, 03:34 PM
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.

darwen
December 29th, 2005, 05:30 PM
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.

NoHero
December 29th, 2005, 05:38 PM
All these functions above are within the Microsoft C Runtime, but not ANSI standard. Here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_c_run.2d.time_libraries.asp) is another resource on this C Runtime. Also be sure your source files using these functions are compiled as unmanaged.

Eliseu_CEL
December 29th, 2005, 08:57 PM
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.

Eliseu_CEL
January 3rd, 2006, 04:38 PM
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...

Eliseu_CEL
January 3rd, 2006, 04:48 PM
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?

darwen
January 3rd, 2006, 05:04 PM
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.

Eliseu_CEL
January 3rd, 2006, 05:10 PM
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.