[SOLVED] clang attach own library

Programming, for all ages and all languages.

Moderators: JAAman, klange, Octocontrabass, sortie, kmcguire, chase, thepowersgang, Owen, Combuster, AJ, 01000101, carbonBased, Candy, pcmattman

Post Reply
User avatar
akasei
Member
Member
Posts: 74
Joined: Tue Feb 11, 2014 4:59 pm

[SOLVED] clang attach own library

Post by akasei »

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 akasei on Thu Nov 10, 2022 11:20 am, edited 1 time in total.
https://blackdev.org/ - system programming, my own 64 bit kernel and software.
nullplan
Member
Member
Posts: 1643
Joined: Wed Aug 30, 2017 8:24 am

Re: clang attach own library

Post by nullplan »

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!
User avatar
akasei
Member
Member
Posts: 74
Joined: Tue Feb 11, 2014 4:59 pm

Re: clang attach own library

Post by akasei »

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.
https://blackdev.org/ - system programming, my own 64 bit kernel and software.
Octocontrabass
Member
Member
Posts: 5218
Joined: Mon Mar 25, 2013 7:01 pm

Re: [SOLVED] clang attach own library

Post by Octocontrabass »

Post Reply