Linker returns quot;relocation has an invalid symbol at symbol index...quot;(链接器返回“重定位在符号索引处有一个无效符号...;)
问题描述
我正在 Ubuntu 上尝试一些代码.我正在尝试运行以下代码
I am trying out some code on Ubuntu. I'm trying to run the following code
#include <cstdlib>
#include <cmath>
#include <ctime>
#include "random.h"
using namespace std;
/* Function prototype! */
void initRandomSeed();
int randomInteger(int low,int high){
initRandomSeed();
double d= rand()/(double(RAND_MAX)+1);
double s= d*(double(high)-low+1);
return int(floor(low)+s);
}
double randomReal(int low,int high){
initRandomSeed();
double d=rand()/(double(RAND_MAX)+1);
double s=d*(double(high)-low+1);
return low+s;
}
bool randomChance(double p){
initRandomSeed();
return randomReal(0,1)<p;
}
void setRandomSeed(int seed){
initRandomSeed();
srand(seed);
}
void initRandomSeed(){
// to retain updated values across different stack frames! nice!
static bool initialized=false;
// this is executed only very first time and random value obtained from system clock!
if(!initialized){
srand(int(time(NULL)));
initialized=true;
}
}
当我尝试使用 g++
编译上述代码时,出现以下错误
And when I try to compile the above code using g++
, I get the following error
@ubuntu:~/Chardway$ g++ random.cpp
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 10
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 10
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 20 has invalid symbol index 19
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
任何有帮助的帮助或问题链接都会非常有帮助!谢谢!
Any help or links to questions that help would be really helpful! Thanks!
推荐答案
我不确定您的无效重定位错误,但明显缺少的是您没有 main
函数.您需要定义一个名为 main
的应用程序入口点,在全局范围内定义,例如:
I'm not sure about your invalid relocation errors but the obvious thing missing is that you have no main
function. You need to define an entry point to your application called main
, defined at global scope such as:
int main()
{
// TODO: implementation
}
这篇关于链接器返回“重定位在符号索引处有一个无效符号...";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:链接器返回“重定位在符号索引处有一个无效符
基础教程推荐
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01