gpt4 book ai didi

c - 未定义的对 rdtsc 的引用

转载 作者:太空宇宙 更新时间:2023-11-04 02:59:35 27 4
gpt4 key购买 nike

<分区>

我正在编写创建树的代码,并使用不同的创建树的方法。不过,我似乎无法让 rdtsc 正常运行。

这是我的代码:

    #include <stdio.h>
#include <stdlib.h>
#define SIZE 10
struct tnode {
int val;
struct tnode *left;
struct tnode *right;
};
struct tnode *addnode(struct tnode *p, long n);
void treeprint(struct tnode *p);

main () {
long data[SIZE]={6, 3, 8, 1, 7, 5, 2, 9, 0, 4};
int i;
struct tnode *node, *root;
unsigned long long rdtsc();
unsigned long long a, b;

printf("size of tnode = %d\n", sizeof(struct tnode));
printf("size of *node = %d\n", sizeof *node);
printf("size of &node = %d\n", sizeof &node);
printf("size of root = %d\n", sizeof root);
printf("size of *root = %d\n", sizeof *root);
printf("size of &root = %d\n", sizeof &root);

a = rdtsc();
root = NULL;
for (i = 0; i < SIZE; i++)
root = addnode(root, data[i]);
b = rdtsc();
treeprint(root);
printf("It took %llu to make this tree.\n", b-a);
}

假设上面列出的所有函数都已处理(当然除了 rdtsc 之外)。

当我尝试编译时,出现此错误:

/tmp/cccnojMf.o: In function `main':
tree.c:(.text+0xd9): undefined reference to `rdtsc'
tree.c:(.text+0x120): undefined reference to `rdtsc'
collect2: ld returned 1 exit status

为什么我会收到这个 undefined reference 错误?

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com