Pelles C > General discussions

Linking error with _rdtsc() function in Pelles C 10

(1/3) > >>

nex42:
Hi, I am new here. I sometimes use Pelles C on Windows.

The program below uses the _rdtsc() function. It builds and runs well on one laptop with Pelles C 9, but not on another laptop with Pelles C 10 because of a linker error. It looks like version 10 does not have _rdtsc()?
Or do I have to install some extra library?

(this is just a little test program to find where the problem is)

/* rdtsc */

#include <stdio.h>
#include <time.h>
#include <math.h>

int main(void)
{
   unsigned long long start, stop;
   double x;

   start = _rdtsc();
   for (int i = 0; i < 1000000; i++)
      x = sqrt(i);
   stop = _rdtsc();
   printf("delta t = %llu\n", stop - start);
}

C:\Users\nex42\Documents\Pelles C Projects\rdtsc\main.c(12): warning #2018: Undeclared function '_rdtsc' (did you mean: rintl?); assuming 'extern' returning 'int'.
Building rdtsc.exe.
POLINK: error: Unresolved external symbol '_rdtsc' - referenced from 'C:\Users\nex42\Documents\Pelles C Projects\rdtsc\output\main.obj'.
POLINK: fatal error: 1 unresolved external(s).

algernon_77:
Hello,

It seems that, for some reason, in v. 10 this function is commented in time.h:


--- Code: ---/* #if __POCC_TARGET__ == 1 || __POCC_TARGET__ == 3
extern unsigned long long __cdecl _rdtsc(void);
#endif */

--- End code ---

If you remove the comments, your example will compile and run just fine

nex42:
Thanks, that worked! :)

Pelle:

--- Quote from: algernon_77 on October 31, 2020, 02:43:44 PM ---If you remove the comments, your example will compile and run just fine

--- End quote ---
Congratulations. Worst. Advice. Ever.


--- Quote from: nex42 on October 31, 2020, 12:04:19 PM ---The program below uses the _rdtsc() function. It builds and runs well on one laptop with Pelles C 9, but not on another laptop with Pelles C 10 because of a linker error. It looks like version 10 does not have _rdtsc()?
Or do I have to install some extra library?

--- End quote ---

The _rdtsc function has been an intrinsic since ~v2.90, so the correct thing to do is add:

--- Code: ---#include <intrin.h>
--- End code ---

algernon_77:
I didn't say that my advice is "best ever" either, just that ,without the comments, that code compiles and works.
And, I quote from the help file:


--- Code: ---Purpose:
Reads the processors Time-Stamp Counter.

Syntax:
unsigned long long _rdtsc(void);

Declared in:
<time.h>

Description:
The _rdtsc function reads the processors Time-Stamp Counter through the X86/X64 RDTSC instruction.

Note! The name __rdtsc may also be used when compiling with Microsoft extensions (the /Ze option is used).

Returns:
The current Time-Stamp Counter value.

See also:
The __rdtscp intrinsic.


--- End code ---

If it's the worst thing ever to use that from time.h, maybe it should be more clear in the docs, or in the header comments, so less gifted people like me would get it.
But, we all have bad days, so I'm ok with it, will take the advice and move on.

Regards.
 

Navigation

[0] Message Index

[#] Next page

Go to full version