OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 11:33 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: [SOLVED] clang attach own library
PostPosted: Thu Nov 10, 2022 5:20 am 
Offline
Member
Member
User avatar

Joined: Tue Feb 11, 2014 4:59 pm
Posts: 74
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:
extern uint8_t font_char_length( uint8_t character );


font.c
Code:
#include   "stdint.h"
#include   "stddef.h"

uint8_t font_char_length( uint8_t character ) {
   return character + 1;
}


main.c
Code:
#include   "stdint.h"
#include   "stddef.h"

#include   "font.h"

void entry() {
   uint8_t length = font_char_length( 0x30 );
}


make.sh
Code:
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}

_________________
https://blackdev.org/ - system programming, my own 64 bit kernel and software.


Last edited by akasei on Thu Nov 10, 2022 11:20 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: clang attach own library
PostPosted: Thu Nov 10, 2022 9:35 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
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!


Top
 Profile  
 
 Post subject: Re: clang attach own library
PostPosted: Thu Nov 10, 2022 11:19 am 
Offline
Member
Member
User avatar

Joined: Tue Feb 11, 2014 4:59 pm
Posts: 74
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.


Top
 Profile  
 
 Post subject: Re: [SOLVED] clang attach own library
PostPosted: Thu Nov 10, 2022 11:32 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
The linker is built into Clang too. The "-c" option tells Clang (or GCC) that you don't want it to link anything.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 28 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group