G++ 尝试将标准库cstdlib中的rand与g+;一起使用时出错+;

G++ 尝试将标准库cstdlib中的rand与g+;一起使用时出错+;,g++,G++,我试图在大型程序上用g++编译Ubuntu时使用random函数,出于某种原因,rand给出了奇怪的编译错误。出于测试目的,我做了我能做的最简单的程序,但它仍然会出错 节目: 您似乎正在将文件链接到自身,从而在生成的可执行文件中产生多个符号定义。请尝试以下方法: g++ chapter_3/tester.cpp 也不要将sudo用于这样的命令。或使用-o标志来g++:g++第三章/tester.cpp-o./test sudo g++ chapter_3/tester.cpp ./test

我试图在大型程序上用g++编译Ubuntu时使用random函数,出于某种原因,rand给出了奇怪的编译错误。出于测试目的,我做了我能做的最简单的程序,但它仍然会出错

节目:



您似乎正在将文件链接到自身,从而在生成的可执行文件中产生多个符号定义。请尝试以下方法:

g++ chapter_3/tester.cpp

也不要将sudo用于这样的命令。

或使用
-o
标志来
g++
g++第三章/tester.cpp-o./test
sudo g++ chapter_3/tester.cpp ./test
./test: In function `_start':
/build/buildd/eglibc-2.10.1/csu/../sysdeps/i386/elf/start.S:65: multiple definition of `_start'
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o:/build/buildd/eglibc-2.10.1/csu/../sysdeps/i386/elf /start.S:65: first defined here
./test:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o:(.rodata+0x0): first defined here
./test: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crti.o:(.fini+0x0): first defined here
./test:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here
./test: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o:(.data+0x0): first defined here
./test: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i486-linux-gnu/4.4.1/crtbegin.o:(.data+0x0): first defined here
./test: In function `main':
(.text+0xb4): multiple definition of `main'
/tmp/cceF0x0p.o:tester.cpp:(.text+0x0): first defined here
./test: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crti.o:(.init+0x0): first defined here
/usr/lib/gcc/i486-linux-gnu/4.4.1/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
./test:(.dtors+0x4): first defined here
/usr/bin/ld: error in ./test(.eh_frame); no .eh_frame_hdr table will be created.
collect2: ld returned 1 exit status
g++ chapter_3/tester.cpp