Home Linking library (from assembly files) with main.c in Makefile
Reply: 0

Linking library (from assembly files) with main.c in Makefile

user2465 Published in April 24, 2018, 6:44 am

Im passionate about assembly and wanted to start coding from home on linux instead of mac I usually use.

I really struggle for 4 days about this issue.

you can find my makefile and clone repository at the following url:

<code>NAME =                libfts.a
ASM_FILES =         ft_isascii  \

OS := $(shell uname)
ifeq ($(OS), Darwin)
ASM_COMPILER =      ~/.brew/bin/nasm -f macho64 -g
ASM_COMPILER =      nasm -f elf64 -g
ASM_SRC_DIR =       srcs/
ASM_OBJ :=          $(addsuffix .o,$(ASM_FILES))
ASM_OBJ :=          $(addprefix $(ASM_OBJ_DIR),$(ASM_OBJ))
TEST =              maintest.out
TEST_FILES =        maintest
C_COMPILER =        clang -Wall -Werror -Wextra -O3
TEST_DIR_NAME =     test
TEST_DIR =          $(TEST_DIR_NAME)/
TEST_OBJ :=         $(addsuffix .o,$(TEST_FILES))
TEST_OBJ :=         $(addprefix $(TEST_DIR),$(TEST_OBJ))
OBJ_PATHS :=        $(ASM_OBJ) $(TEST_OBJ)
all: $(NAME)
    ar rc $(NAME) $(ASM_OBJ)
test: re $(TEST_OBJ)
    $(C_COMPILER) -L. $(NAME) $(TEST_OBJ) -o $(TEST)
$(ASM_OBJ): $(ASM_OBJ_DIR)%.o: $(ASM_SRC_DIR)%.s
    @/bin/mkdir -p $(ASM_OBJ_DIR)
    $(ASM_COMPILER) $< -o $@
$(TEST_OBJ): $(TEST_DIR)%.o: $(TEST_DIR)%.c
    $(C_COMPILER) -c -I. $< -o $@
    -/bin/rm -f $(OBJ_PATHS)
    /usr/bin/find . -name "$(ASM_OBJ_DIR_NAME)" -maxdepth 1 -type d -empty -delete
fclean: clean
    -/bin/rm -f $(NAME)
    -/bin/rm -f $(TEST)
re: fclean all
.PHONY: all clean fclean re

I have this error message when I try "make test" on the linux:

    test/maintest.o: In function `main':
    test/maintest.c:(.text+0x33): undefined reference to `ft_isascii'
    undefined reference to etc.

.h content:

#ifndef _LIBFTS
# define _LIBFTS

#include <stddef.h>

int         ft_isascii(int c);


ft_isascii.s content:

global _ft_isascii

section .text

_ft_isascii:                ; int ft_isascii
    and     edi, 0xffffff80 ; mask with the 128 firsts bits left to 0 as ASCII range from 0 to 7f in hexa (just below 80)
    sete    al              ; SETE sets AL to 1 if above condition code means "equal", otherwise it sets AL to 0.
    movzx   eax, al

I would REALLY be thanksful for any tips to solve this issue...


You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308606 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO