Programming, for all ages and all languages.
CorruptedByCPU
Member
Posts: 78 Joined: Tue Feb 11, 2014 4:59 pm
Post
by CorruptedByCPU » Thu Nov 10, 2022 5:20 am
Hey! I'm trying to bind a library to a program, but clang insistently does not see it or doesn't recognize it.
Can someone give me a hint?
clang-14: warning: -lfont: 'linker' input unused [-Wunused-command-line-argument]
clang-14: warning: argument unused during compilation: '-L.' [-Wunused-command-line-argument]
ld: main.o: in function `entry':
main.c:(.text+0x6): undefined reference to `font_char_length'
font.h
Code: Select all
extern uint8_t font_char_length( uint8_t character );
font.c
Code: Select all
#include "stdint.h"
#include "stddef.h"
uint8_t font_char_length( uint8_t character ) {
return character + 1;
}
main.c
Code: Select all
#include "stdint.h"
#include "stddef.h"
#include "font.h"
void entry() {
uint8_t length = font_char_length( 0x30 );
}
make.sh
Code: Select all
CFLAGS="-Ofast -march=x86-64 -nostdlib -fomit-frame-pointer -fno-builtin -fno-stack-protector -m64 -mno-red-zone -fno-asynchronous-unwind-tables"
LDFLAGS="-nostdlib -zmax-page-size=0x1000 -static -no-dynamic-linker"
clang -c -fpic font.c ${CFLAGS}
clang -shared -o libfont.so font.o ${CFLAGS}
clang -L. -c main.c -o main.o -lfont ${CFLAGS}
ld main.o -o main -T linker.software ${LDFLAGS}
Last edited by
CorruptedByCPU on Thu Nov 10, 2022 11:20 am, edited 1 time in total.
nullplan
Member
Posts: 1766 Joined: Wed Aug 30, 2017 8:24 am
Post
by nullplan » Thu Nov 10, 2022 9:35 am
You are giving linker command line flags to the compiler. That will not work. Try removing the -L and -l options from the second-to-last line and adding them to the last line of make.sh.
Carpe diem!
CorruptedByCPU
Member
Posts: 78 Joined: Tue Feb 11, 2014 4:59 pm
Post
by CorruptedByCPU » Thu Nov 10, 2022 11:19 am
nullplan wrote: You are giving linker command line flags to the compiler. That will not work. Try removing the -L and -l options from the second-to-last line and adding them to the last line of make.sh.
It worked! Thank you
My mistake was that I saw an example from GCC and the linker was built-in there.