-1

I try to include static library gmp.h but Linux can not see it. Terminal output like this: gcc -Wall -Werror -Wextra -std=c11 -D OS_LINUX -I/../materials/LINUX_gmp_lib/include/ -L/../materials/LINUX_gmp_lib/lib -lgmp -c s21_*.c ar rc s21_decimal.a s21_*.o ranlib s21_decimal.a gcc -Wall -Werror -Wextra -std=c11 -D OS_LINUX -lgmp tests.c s21_decimal.a -lpthread -lcheck -pthread -lm -lrt -o test /usr/bin/ld: невозможно найти -lgmp: Нет такого файла или каталога collect2: error: ld returned 1 exit status make: *** [Makefile:31: test] Ошибка 1 my makefile look like this:

#.SILENT:

CC = gcc -Wall -Werror -Wextra -std=c11
GCOVFLAGS = -fprofile-arcs -ftest-coverage
LIBS = -lcheck 
PROJECTNAME = s21_decimal

OS := $(shell uname -s)
ifeq ($(OS), Darwin)
    CC += -D OS_MAC
    GMP_PATH = -I/../materials/MAC_gmp_lib/include/ -L/../materials/MAC_gmp_lib/lib
    TEST_FLAGS = $(LIBS)
    GMP_FLAGS = -lgmp -Wl,-no_pie
    
endif
ifeq ($(OS), Linux)
    CC += -D OS_LINUX
    GMP_PATH = -I/../materials/LINUX_gmp_lib/include/ -L/../materials/LINUX_gmp_lib/lib
    TEST_FLAGS = -lpthread $(LIBS) -pthread  -lm -lrt
    GMP_FLAGS = -lgmp 
endif

all: $(PROJECTNAME).a

$(PROJECTNAME).a: clean
    ${CC} ${GMP_PATH} ${GMP_FLAGS} -c s21_*.c
    ar rc $(PROJECTNAME).a s21_*.o
    ranlib $(PROJECTNAME).a

test: $(PROJECTNAME).a
    ${CC} ${GMP_FLAGS} tests.c $(PROJECTNAME).a $(TEST_FLAGS) -o test
    ./test

gcov_report: clean
    @${CC} ${GMP_FLAGS} $(GCOVFLAGS) s21_*.c tests.c $(TEST_FLAGS) -o test_report $(LIBS)
    @./test_report
    @lcov -t test_report -o test.info -c -d .
    @genhtml -o report test.info
    @open ./report/index-sort-f.html

rebuild: clean all

clean:
    -rm -rf $(PROJECTNAME)
    -rm -rf *.gcda
    -rm -rf *.gcno
    -rm -rf *.a
    -rm -rf *.o
    -rm -rf test
    -rm -rf test_report
    -rm -rf test.info
    -rm -rf report
    clear

clang:
    clang-format --style=Google -n *.c *.h
    clang-format --style=Google -i *.c *.h


GPT say to replace arguments but it doesnot work test: $(PROJECTNAME).a ${CC} tests.c $(PROJECTNAME).a $(TEST_FLAGS) -o test ${GMP_PATH} ${GMP_FLAGS} ./test -Wl,-no_pie also doesnot work

try to replace arguments add -Wl,-no_pie om mac this code work good but linux doesnot work. I think Linux try to find library by default adress. I ca use only static library in this project

  • The Russian error message translates (by Google) as `cannot find -lgmp: No such file or directory`. So it sounds like you don't have the correct `-L` option(s) to gcc or the linker. – pmacfarlane Aug 27 '23 at 21:35
  • Can you please put the "terminal output" into a properly formatted code block? As it is, it is all mashed together and difficult to read. – pmacfarlane Aug 27 '23 at 21:36
  • It doesn't make sense to have -l flags in a gcc invocation that also has -c. `-L/../materials` doesn't make sense either, maybe removing the leading slash if this is a relative path. – Marc Glisse Aug 28 '23 at 06:51
  • -L options is link to gmp.a – Chat Chatovich Aug 28 '23 at 07:00
  • term-l: **gcc -Wall -Werror -Wextra -std=c11 -D OS_LINUX -I/../materials/LINUX_gmp_lib/include/ -L/../materials/LINUX_gmp_lib/lib -lgmp -c s21_*.c ar rc s21_decimal.a s21_*.o ranlib s21_decimal.a gcc -Wall -Werror -Wextra -std=c11 -D OS_LINUX -lgmp tests.c s21_decimal.a -lpthread -lcheck -pthread -lm -lrt -o test /usr/bin/ld:cant find-lgmp: NO file or dir collect2: error: ld returned 1 exit status make: * [Makefile:31: test] error 1** alsoo i try to delete slash : 'GMP_PATH = -I../materials/LINUX_gmp_lib/include/ -L../materials/LINUX_gmp_lib/lib' eror in terminal the same – Chat Chatovich Aug 28 '23 at 07:19
  • Project can be duild but test is error I think problem in : ./configure --prefix=/Users/effiekel/Desktop/1 --disable-shared --enable-static maybe I need write something more in this because: /usr/bin/ld: can not find -lgmp: no file or directory collect2: error: ld returned 1 exit status make: *** [Makefile:31: test] Eror 1 – Chat Chatovich Aug 28 '23 at 09:46
  • Please don't post additional/crritical information about your problem in comments. Add that information at the bottom of your question, preceded by the word **`edit`**. Add a comment to the bottom, "please see my edits above". Also re-read and act upon the 2nd comment above. Good luck. – shellter Aug 28 '23 at 13:37

0 Answers0