Riscv32-unknown-elf Linker Error after reading linker script : undefined reference to '_end' - c

I'm trying to compile and link a custom made c code to risc v project but I'm getting these error in the making:
I'm new to this field so please excuse any mistakes.
/local/home/opt/riscv/lib/gcc/riscv32-unknown-elf/9.2.0/../../../../riscv32-unknown-elf/bin/ld:
/local/home/opt/riscv/lib/gcc/riscv32-unknown-elf/9.2.0/../../../../riscv32-unknown-elf/lib/crt0.o:
in function `_start':
(.text+0x0): undefined reference to `__global_pointer$'
/local/home/s2500108/riscv/lib/gcc/riscv32-unknown-elf/9.2.0/../../../../riscv32-unknown-elf/bin/ld: (.text+0x8): undefined reference to `_edata'
/local/home/s2500108/riscv/lib/gcc/riscv32-unknown-elf/9.2.0/../../../../riscv32-unknown-elf/bin/ld: (.text+0x10): undefined reference to `_end'
collect2: error: ld returned 1 exit status
I also wanted to ask this:
After executing ./configure --prefix=/local/home/s2500108/riscv --with-abi=ilp32 --with-arch=rv32i
+ make
and trying to compile a multiplication instruction in c code examle a=21, b=10; a * b the compiler does not output any error and produces elf files normally. Why is this happening? I want to make sure that no multiplication will take place.

Related

Linker Complains Undefined Reference Under MINIX3.2.1

As you may imagine, it's a homework of Operating Systems and I'm asked to add function key Shift+F7 to show the number of running process.
I read the source code of command ps on GitHub (MINIX version 3.2.1) and try to implement a function that can finish the task in file /usr/src/servers/is/dmp_kernel.c. However, when I try to run make, it complains about undefined reference like
dmp_kernel.o: In function `running_proc_num':
dmp_kernel.c:(.text+0x1e): undefined reference to `chdir'
dmp_kernel.c:(.text+0x42): undefined reference to `fopen'
dmp_kernel.c:(.text+0x72): undefined reference to `fscanf'
dmp_kernel.c:(.text+0x8b): undefined reference to `fclose'
dmp_kernel.c:(.text+0xc4): undefined reference to `log10'
dmp_kernel.c:(.text+0xcc): undefined reference to `ceil'
dmp_kernel.c:(.text+0x119): undefined reference to `log10'
dmp_kernel.c:(.text+0x121): undefined reference to `ceil'
dmp_kernel.c:(.text+0x170): undefined reference to `fopen'
dmp_kernel.c:(.text+0x1bc): undefined reference to `fscanf'
dmp_kernel.c:(.text+0x1d3): undefined reference to `fclose'
dmp_kernel.c:(.text+0x210): undefined reference to `wait'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've already include the headers like stdio.h, math.h, unistd.h, and sys/wait.h. In the answer to one Stack Overflow question, I learnt that the reason for this issue is that the linker doesn't link a complete C library under MINIX. However, I usually use CMake and really have no idea to solve such issue. I don't even know how to "explicitly" link the functions using make.
I really look forward for your help!
The Makefile looks like
.include <bsd.own.mk>
PROG= is
SRCS= main.c dmp.c dmp_kernel.c dmp_pm.c dmp_fs.c dmp_rs.c dmp_ds.c dmp_vm.c
DPADD+= ${LIBSYS}
LDADD+= -lsys
MAN=
BINDIR?= /sbin
CPPFLAGS.dmp_kernel.c+= -I${NETBSDSRCDIR}
CPPFLAGS.dmp_rs.c+= -I${NETBSDSRCDIR}
CPPFLAGS.dmp_vm.c+= -I${NETBSDSRCDIR}
# This setting must match the kernel's, as it affects the IRQ hooks table size.
.if ${USE_APIC} != "no"
CFLAGS+= -DUSE_APIC
.endif
.include <minix.service.mk>

Failing to compile a 15+ year old MUD codebase written in C

I used this codebase to run a mud in the early 2000s, and through that, to teach myself some very elementary coding.
I just got a copy of the codebase from the administrator/coder who ran the server before me, and I'm just about certain that it would compile as-is back then, but now it won't.
My only guess is that it has something to do with updates to GCC in the last 15-20 years, but I'm admittedly a novice and pretty out of my depth here.
This is the error I get after about a hundred pages of warnings when I try to compile it using make:
[18:24:54] finger.c ...
In file included from finger.c:10:0:
../src/include/merc.h:5149:13: warning: inline function ‘check_toughness’ declared but never defined
inline int check_toughness args( ( CD *ch, CD *victim, int dam));
^~~~~~~~~~~~~~~
[18:24:54] Linking Executable ...
obj/fight.o: In function `group_gain':
tbw/reloaded/src/fight.c:5514: undefined reference to `xp_compute'
tbw/reloaded/src/fight.c:5516: undefined reference to `xp_compute'
tbw/reloaded/src/fight.c:5518: undefined reference to `xp_compute'
obj/fight.o: In function `one_hit':
tbw/reloaded/src/fight.c:2457: undefined reference to `check_toughness'
obj/mage.o: In function `do_chant':
tbw/reloaded/src/mage.c:345: undefined reference to `check_toughness'
tbw/reloaded/src/mage.c:361: undefined reference to `check_toughness'
tbw/reloaded/src/mage.c:377: undefined reference to `check_toughness'
tbw/reloaded/src/mage.c:393: undefined reference to `check_toughness'
obj/mage.o:tbw/reloaded/src/mage.c:409: more undefined references to `check_toughness' follow
obj/update.o: In function `mobile_update':
tbw/reloaded/src/update.c:756: undefined reference to `werewolf_regen'
obj/powerl.o: In function `do_planarstorm':
tbw/reloaded/src/powerl.c:680: undefined reference to `check_toughness'
collect2: error: ld returned 1 exit status
Makefile:27: recipe for target '../src/reloaded' failed
make: *** [../src/reloaded] Error 1
The codebase and the referenced files are huge, so I figured it wouldn't make sense to attach them just yet, but if required I can definitely provide them.
For the record, those functions like "check_toughness" and "xp_compute" are definitely defined within those files after a few thousand LOC.
Would appreciate any suggestions, thank you!
Thank you to everyone who came in with suggestions!
The simplest answer was provided by rici:
That is probably the result of the code using the old idiosyncratic gcc semantics for inline. Try compiling with --std=gnu89 (if you are using gcc).
Adding that to the Makefile cleared up all the errors and resulted in a successful compile.

how to use "make and building executables" in Linux work [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 6 years ago.
i tried to use make on my c source code and created executable file. but the executable file did not work the intended task. even if the make file compiled and produced the executable file when i try to compile the .c file individually it gave many undefined reference problem
The errors are
/tmp/cc4tx0BG.o: In function `main':
cubist.c:(.text+0xdc): undefined reference to `Of'
cubist.c:(.text+0xe7): undefined reference to `Of'
cubist.c:(.text+0xfa): undefined reference to `Of'
cubist.c:(.text+0x10f): undefined reference to `KRInit'
cubist.c:(.text+0x114): undefined reference to `ExecTime'
cubist.c:(.text+0x127): undefined reference to `PrintHeader'
cubist.c:(.text+0x139): undefined reference to `Of'
[...]
cubist.c:(.text+0xb79): undefined reference to `MaxAtt'
cubist.c:(.text+0xb83): undefined reference to `InitialiseEnvData'
cubist.c:(.text+0xb8a): undefined reference to `XVAL'
cubist.c:(.text+0xb93): undefined reference to `CrossVal'
cubist.c:(.text+0xb9a): undefined reference to `SingleCttee'
cubist.c:(.text+0xb9f): undefined reference to `ExecTime'
cubist.c:(.text+0xbab): undefined reference to `Of'
collect2: error: ld returned 1 exit status
please, could any body tells how to use make and building executables in Linux work.
I think (not sure) that you are saying that you successfully produced an executable using Make (at least that's how I interpret "use make on my c source code and created executable file" -- do correct me if I'm wrong!). If that's the case, invoke make like this: make -B --trace, and you'll see the exact commands that were used to build the executable, and then you'll hopefully know which compiler/linker flags or libraries you missed while trying to build stuff manually.

Struggling compiling a simple c program (gcc)

I have a very old C program and want to compile to Windows. So I try doing this:
gcc -DNO_GLIBC=1 sakide.c -o sakide.exe
and this returns:
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0xa4): undefined reference to `ekiGetLibVersion'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x6b6): undefined reference to `ekiGetLibVersion'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x8ff): undefined reference to `ekiEncodeUrl'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x954): undefined reference to `ekiDecodeUrl'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x993): undefined reference to `ekiDecodeUrl'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0xa62): undefined reference to `ekiGetKeyInfo'
collect2.exe: error: ld returned 1 exit status
This ekiGetLibVersion is in a .h file:
INT EKIAPI ekiGetLibVersion(char *outBuffer, LPINT outBufferSize);
and I also have a .dll name of it.
Ive never compiled anything with C though
On windows you cannot link against directly with the .dll, you have to link the import library, name .lib. For more information, refer:
On dynamic linking:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682592(v=vs.85).aspx
On implicit linking:
https://msdn.microsoft.com/en-us/library/d14wsce5.aspx
You are getting linker errors.
You need to link the library (or object file) where those functions are defined.
Undefined reference usually means the compiler has not seen a proper declaration for this variable. Did you include the header file (which defines this variable) in your C program ?
#include "header_file.h"

make error using GNU/GCC quad precision library

When using Cygwin and GCC under Win 7 and the quad precision library:
gcc -c lquad.c
... this runs OK, but
gcc lquad.o
... produces the following error:
/tmp/ccLM2lOn.o:lquad.c:(.text+0xdb3): undefined reference to `sqrtq'
collect2: error: ld returned 1 exit status
I have #include quadmath.h in a C source, and the __float128 type works, but not the functions (e.g. sqrtq above). This header file has all the relevant externs, e.g.:
extern __float128 sqrtq (__float128) __quadmath_throw;
I found a dll cygquadmath-0.dll which definitely has these functions in it. It is in 3 places in the Cygwin installation. Additionally, I copied it to Windows\System, but that did not help.
There is a related question here, but nothing helped me there and it is not exactly the same error: Quadruple Precision in C++ (GCC)
You are looking for a compiler solution when what you need is a linker solution:
Your code is compiling as it should, so no change in the code would solve your problem:
/tmp/ccLM2lOn.o:lquad.c:(.text+0xdb3): undefined reference to `sqrtq'
collect2: error: ld returned 1 exit status
The undefined reference to errors indicate a function needed by your object is in another library.
As suggested by #Marc Glisse, try adding -lquadmath to your linker line.

Resources