/* main.cpp */
int main() { return 0; }
< /code>
/* syscalls.cpp */
#include
extern "C" {
caddr_t _sbrk (intptr_t) { return (caddr_t)0; }
int _close(int) { return -1; }
int _write (int, char*, int) { return 0; }
int _lseek(int, int, int) { return 0; }
int _read (int, char*, int) { return 0; }
void _exit (int) { while(1); }
}
< /code>
/* Makefile */
CC = aarch64-none-elf-g++
LIBS = -lc -lgcc -lstdc++
all: myexe.elf
%.o: %.cpp
$(CC) -std=gnu++20 -c $<
syscalls.a: syscalls.o
ar -rsc syscalls.a syscalls.o
myexe.elf: main.o syscalls.a
$(CC) -Wl,--start-group $^ $(LIBS) -Wl,--end-group -o $@
clean:
rm -rf myexe.elf *.o *.a
.PHONY: all clean
< /code>
However, during linking the linker complains that it can not resolve some symbols as those are not defined (In this case system calls, such as, _close...):
...
.../libc.a(libc_a-lseekr.o): in function `_lseek_r':
(.text+0x28): undefined reference to `_lseek'
.../libc.a(libc_a-closer.o): in function `_close_r':
(.text+0x20): undefined reference to `_close'
...
< /code>
This error seems to make sense as the following linker invocation
/* Makefile */
...
$(CC) -Wl,--start-group $^ $(LIBS) -Wl,--end-group -o $@
< /code>
results in the libc being removed from the "start-end-group" (Cyclic dependency group):
collect2 ... --start-group main.o syscalls.a -lgcc -lstdc++ --end-group -lstdc++ -lm -lgcc -lc -lgcc ...
< /code>
In this context, I have two questions:
[list]
[*]Why is the libc removed from the "start-end-group" despite the explicit inclusion (Since I am not that familiar with the gcc project, I haven't yet found the code snippet in the GCC project producing this behaviour)
[*]Why is the libc only removed once from the "start-end-group" (Using --start-group ... -lc -lc ... --end-group
Результаты-Start-Group ... -lc ...-ind-group , а связь успешна)
[/list]
Я переполняю пример проекта на Linux для нацеливания на кору Cortexa72. Мой проект состоит из следующих файлов: < /p> [code]/* main.cpp */ int main() { return 0; } < /code> /* syscalls.cpp */ #include
.PHONY: all clean < /code> However, during linking the linker complains that it can not resolve some symbols as those are not defined (In this case system calls, such as, _close...): ... .../libc.a(libc_a-lseekr.o): in function `_lseek_r': (.text+0x28): undefined reference to `_lseek' .../libc.a(libc_a-closer.o): in function `_close_r': (.text+0x20): undefined reference to `_close' ... < /code> This error seems to make sense as the following linker invocation /* Makefile */ ... $(CC) -Wl,--start-group $^ $(LIBS) -Wl,--end-group -o $@ < /code> results in the libc being removed from the "start-end-group" (Cyclic dependency group): collect2 ... --start-group main.o syscalls.a -lgcc -lstdc++ --end-group -lstdc++ -lm -lgcc -lc -lgcc ... < /code> In this context, I have two questions: [list] [*]Why is the libc removed from the "start-end-group" despite the explicit inclusion (Since I am not that familiar with the gcc project, I haven't yet found the code snippet in the GCC project producing this behaviour) [*]Why is the libc only removed once from the "start-end-group" (Using --start-group ... -lc -lc ... --end-group[/code] Результаты-Start-Group ... -lc ...-ind-group , а связь успешна) [/list]