LIBC удален из циклической группы зависимостей во время связыванияC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 LIBC удален из циклической группы зависимостей во время связывания

Сообщение Anonymous »

Я переполняю пример проекта на Linux для нацеливания на кору Cortexa72. Мой проект состоит из следующих файлов: < /p>

Код: Выделить всё

/* 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]

Подробнее здесь: https://stackoverflow.com/questions/796 ... ng-linking
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»