1

I use Embarcadero C++Builder 10.2 Tokyo (Community Edition).

I try to use the RoundTo() function. I can use it in a VCL project by adding the <Math.hpp> header, but in a Console project I can not use this function at all. I get 2 error messages:

[ilink32 Error] Error: Unresolved external '__fastcall System :: Math :: RoundTo (const long double, const signed char)' referenced from C: \ USERS \ ... \ ROUNDTOCONSOLE \ WIN32 \ DEBUG \ ROUNDTOCONSOLE.OBJ

and

[ilink32 Error] Error: Unable to perform link

Please tell me how to use this function in a Console project? What library or namespace do I need to use? And why can I use it in a VCL project, is there a problem in the console?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
forritarik
  • 35
  • 4
  • Not really a duplicate. This IDE is a bit peculiar with linker and library settings. It's not as easy as to add relevelant files to the project, but rather to find the right checkbox in some menu. – Lundin Apr 23 '19 at 10:43
  • As for the question, these are VCL libs. Simply avoid them if you aren't using VCL. There's equivalent standard C++ functions you can use instead. – Lundin Apr 23 '19 at 10:46
  • ok do you know any equivalent functions for rounding floating point numbers in the console? – forritarik Apr 23 '19 at 12:26
  • 1
    Create a console app with the VCL as library. That can be set in the wizard. The unit, *System.Math*, is actually not part of the VCL, but since it is a Delphi unit, for C++Builder it has always been considered "VCL". – Rudy Velthuis Apr 23 '19 at 13:19
  • `round`, `trunc`, `modf` etc in the C standard lib. – Lundin Apr 23 '19 at 13:19
  • @Lundin: not all of these are actually implemented. AFAIK, they are still missing or reported as bug in Rio 10.3.1. – Rudy Velthuis Apr 23 '19 at 13:21
  • Still, it ain't rocket science. You can roll out a naive implementation yourself in 10 seconds: `int my_int = (int)my_float;` then `my_float = (my_float - my_int < 0.5f) ? (float)my_int : (float)(my_int + 1);` Just gotta have float size and precision in mind. – Lundin Apr 23 '19 at 13:27
  • @Lundin: `System::Math::RoundTo()` gives you the opportunity to round to a given number of decimals (digits after the decimal point). That is not the same as *std::round()*. Instead, OP can simply use the "VCL" (and Delphi runtime, to which `RoundTo` actually belongs) by selecting that library (VCL) in the console wizard (*New -> Other -> C++Builder Projects -> Console application* or similar path) – Rudy Velthuis Apr 23 '19 at 20:45
  • @Lundin: http://docwiki.embarcadero.com/Libraries/Rio/en/System.Math.RoundTo. `round` in the C standard lib is not an alternative. – Rudy Velthuis Apr 23 '19 at 20:50
  • 2
    @forritarik when you create new console project you just simply check the VCL checker in the dialog box (unless they change it as I am using older borland IDE)... that will add all the linking switches and include to your project... and you can use all he VCL stuff in console just like in Form App... – Spektre Apr 24 '19 at 07:24

0 Answers0