alelievr / libft-unit-test

457 stars 88 forks source link

does not compile on linux #19

Closed nekitoss closed 7 years ago

nekitoss commented 7 years ago

i'm trying to run test on this system:

$ uname -a
Linux computername 4.4.0-47-generic #68~14.04.1-Ubuntu SMP Wed Oct 26 19:42:11 UTC 2016 x86_64 x86_64 x86_64 GNU/Linu

i've have right structure of files&folders (already run tests on mac, wanted to test at home) i've tried to make sudo chmod 777 -R for both folders i've tried to run make re with sudo gcc is:

$ gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4

clang version:

$ clang --version
Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu
Thread model: posix

but i'm getting next error (i've added -v flag to CSOFLAGS):


~/libft-unit-test$ make re
 make -j 3 re -C ../libft 
make[1]: Entering directory `/home/username/libft'
/bin/rm -f ft_bzero.o ft_isdigit.o ft_memset.o ft_strcmp.o ft_strlen.o ft_strnstr.o ft_toupper.o ft_isalnum.o ft_isprint.o ft_strcat.o ft_strcpy.o ft_strncat.o ft_strrchr.o ft_isalpha.o ft_memccpy.o ft_strchr.o ft_strdup.o ft_strncmp.o ft_strstr.o  ft_atoi.o ft_isascii.o ft_memcpy.o ft_strclr.o ft_strlcat.o ft_strncpy.o ft_tolower.o ft_memmove.o ft_memchr.o ft_memcmp.o
gcc -Wall -Werror -Wextra -I./ -c  ft_bzero.c ft_isdigit.c ft_memset.c ft_strcmp.c ft_strlen.c ft_strnstr.c ft_toupper.c ft_isalnum.c ft_isprint.c ft_strcat.c ft_strcpy.c ft_strncat.c ft_strrchr.c ft_isalpha.c ft_memccpy.c ft_strchr.c ft_strdup.c ft_strncmp.c ft_strstr.c  ft_atoi.c ft_isascii.c ft_memcpy.c ft_strclr.c ft_strlcat.c ft_strncpy.c ft_tolower.c ft_memmove.c ft_memchr.c ft_memcmp.c
/bin/rm -f libft.a
ar rc libft.a ft_bzero.o ft_isdigit.o ft_memset.o ft_strcmp.o ft_strlen.o ft_strnstr.o ft_toupper.o ft_isalnum.o ft_isprint.o ft_strcat.o ft_strcpy.o ft_strncat.o ft_strrchr.o ft_isalpha.o ft_memccpy.o ft_strchr.o ft_strdup.o ft_strncmp.o ft_strstr.o  ft_atoi.o ft_isascii.o ft_memcpy.o ft_strclr.o ft_strlcat.o ft_strncpy.o ft_tolower.o ft_memmove.o ft_memchr.o ft_memcmp.o
ranlib libft.a 
make[1]: Leaving directory `/home/username/libft'
[  Cleaning #0  ]
➤  rm -f obj/src/main.o obj/src/test_functions.o obj/src/display_test_result.o obj/src/signal.o obj/src/sandbox.o obj/src/bench_functions.o obj/hardcore-mode/hardcore-main.o obj/hardcore-mode/error.o obj/hardcore-mode/ncurses-display.o obj/hardcore-mode/test-init.o obj/hardcore-mode/test-utils.o obj/hardcore-mode/test-strcpy.o obj/hardcore-mode/test-strcmp.o obj/hardcore-mode/test-strncmp.o obj/hardcore-mode/test-memset.o obj/hardcore-mode/test-memcpy.o obj/hardcore-mode/test-memccpy.o obj/hardcore-mode/test-memmove.o obj/hardcore-mode/test-memchr.o obj/hardcore-mode/test-memcmp.o obj/hardcore-mode/test-strlen.o obj/hardcore-mode/test-strncpy.o obj/hardcore-mode/test-strcat.o obj/hardcore-mode/test-strncat.o obj/hardcore-mode/test-strchr.o obj/hardcore-mode/test-strrchr.o obj/hardcore-mode/test-strstr.o 
➤  rm -f libft.so assets/libft.a assetslibtests assets/malloc.dylib 
➤  rm -f run_test 
 make -j 3 -C ../libft 
make[1]: Entering directory `/home/username/libft'
gcc -Wall -Werror -Wextra -I./ -c  ft_bzero.c ft_isdigit.c ft_memset.c ft_strcmp.c ft_strlen.c ft_strnstr.c ft_toupper.c ft_isalnum.c ft_isprint.c ft_strcat.c ft_strcpy.c ft_strncat.c ft_strrchr.c ft_isalpha.c ft_memccpy.c ft_strchr.c ft_strdup.c ft_strncmp.c ft_strstr.c  ft_atoi.c ft_isascii.c ft_memcpy.c ft_strclr.c ft_strlcat.c ft_strncpy.c ft_tolower.c ft_memmove.c ft_memchr.c ft_memcmp.c
ar rc libft.a ft_bzero.o ft_isdigit.o ft_memset.o ft_strcmp.o ft_strlen.o ft_strnstr.o ft_toupper.o ft_isalnum.o ft_isprint.o ft_strcat.o ft_strcpy.o ft_strncat.o ft_strrchr.o ft_isalpha.o ft_memccpy.o ft_strchr.o ft_strdup.o ft_strncmp.o ft_strstr.o  ft_atoi.o ft_isascii.o ft_memcpy.o ft_strclr.o ft_strlcat.o ft_strncpy.o ft_tolower.o ft_memmove.o ft_memchr.o ft_memcmp.o
ranlib libft.a 
make[1]: Leaving directory `/home/username/libft'
 cp ../libft/libft.a assets/ 
 clang -shared -fPIC -v assets/tmp/ft_atoi.o assets/tmp/ft_bzero.o assets/tmp/ft_isalnum.o assets/tmp/ft_isalpha.o assets/tmp/ft_isascii.o assets/tmp/ft_isdigit.o assets/tmp/ft_isprint.o assets/tmp/ft_memccpy.o assets/tmp/ft_memchr.o assets/tmp/ft_memcmp.o assets/tmp/ft_memcpy.o assets/tmp/ft_memmove.o assets/tmp/ft_memset.o assets/tmp/ft_strcat.o assets/tmp/ft_strchr.o assets/tmp/ft_strclr.o assets/tmp/ft_strcmp.o assets/tmp/ft_strcpy.o assets/tmp/ft_strdup.o assets/tmp/ft_strlcat.o assets/tmp/ft_strlen.o assets/tmp/ft_strncat.o assets/tmp/ft_strncmp.o assets/tmp/ft_strncpy.o assets/tmp/ft_strnstr.o assets/tmp/ft_strrchr.o assets/tmp/ft_strstr.o assets/tmp/ft_tolower.o assets/tmp/ft_toupper.o -o libft.so 
Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.4
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.3
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.3
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
 "/usr/bin/ld" -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -shared -o libft.so /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/crtbeginS.o -L/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../.. -L/lib -L/usr/lib assets/tmp/ft_atoi.o assets/tmp/ft_bzero.o assets/tmp/ft_isalnum.o assets/tmp/ft_isalpha.o assets/tmp/ft_isascii.o assets/tmp/ft_isdigit.o assets/tmp/ft_isprint.o assets/tmp/ft_memccpy.o assets/tmp/ft_memchr.o assets/tmp/ft_memcmp.o assets/tmp/ft_memcpy.o assets/tmp/ft_memmove.o assets/tmp/ft_memset.o assets/tmp/ft_strcat.o assets/tmp/ft_strchr.o assets/tmp/ft_strclr.o assets/tmp/ft_strcmp.o assets/tmp/ft_strcpy.o assets/tmp/ft_strdup.o assets/tmp/ft_strlcat.o assets/tmp/ft_strlen.o assets/tmp/ft_strncat.o assets/tmp/ft_strncmp.o assets/tmp/ft_strncpy.o assets/tmp/ft_strnstr.o assets/tmp/ft_strrchr.o assets/tmp/ft_strstr.o assets/tmp/ft_tolower.o assets/tmp/ft_toupper.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/crtendS.o /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
/usr/bin/ld: assets/tmp/ft_isalnum.o: relocation R_X86_64_PC32 against symbol `ft_isalpha' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libft.so] Error 1
alelievr commented 7 years ago

Hello,

are you on the linux branch of the project ?

nekitoss commented 7 years ago

okay, that was my fault. Plz add to description that user has to change branch! Also i had to change shell - /bin/bash worked for me (also will be good to see in description) but i still get an error (-v did not changed output) :


$ make re
\033[38;5;46m make re -C ../libft \033[31m
make[1]: Entering directory `/home/username/libft'
/bin/rm -f ft_bzero.o ft_isdigit.o ft_memset.o ft_strcmp.o ft_strlen.o ft_strnstr.o ft_toupper.o ft_isalnum.o ft_isprint.o ft_strcat.o ft_strcpy.o ft_strncat.o ft_strrchr.o ft_isalpha.o ft_memccpy.o ft_strchr.o ft_strdup.o ft_strncmp.o ft_strstr.o  ft_atoi.o ft_isascii.o ft_memcpy.o ft_strclr.o ft_strlcat.o ft_strncpy.o ft_tolower.o ft_memmove.o ft_memchr.o ft_memcmp.o
/bin/rm -f libft.a
gcc -Wall -Werror -Wextra -I./ -c  ft_bzero.c ft_isdigit.c ft_memset.c ft_strcmp.c ft_strlen.c ft_strnstr.c ft_toupper.c ft_isalnum.c ft_isprint.c ft_strcat.c ft_strcpy.c ft_strncat.c ft_strrchr.c ft_isalpha.c ft_memccpy.c ft_strchr.c ft_strdup.c ft_strncmp.c ft_strstr.c  ft_atoi.c ft_isascii.c ft_memcpy.c ft_strclr.c ft_strlcat.c ft_strncpy.c ft_tolower.c ft_memmove.c ft_memchr.c ft_memcmp.c
ar rc libft.a ft_bzero.o ft_isdigit.o ft_memset.o ft_strcmp.o ft_strlen.o ft_strnstr.o ft_toupper.o ft_isalnum.o ft_isprint.o ft_strcat.o ft_strcpy.o ft_strncat.o ft_strrchr.o ft_isalpha.o ft_memccpy.o ft_strchr.o ft_strdup.o ft_strncmp.o ft_strstr.o  ft_atoi.o ft_isascii.o ft_memcpy.o ft_strclr.o ft_strlcat.o ft_strncpy.o ft_tolower.o ft_memmove.o ft_memchr.o ft_memcmp.o
ranlib libft.a 
make[1]: Leaving directory `/home/username/libft'
\033[38;5;196;m[  Cleaning #0  ]\033[0m
\033[38;5;196m➤ \033[38;5;9m rm -f obj/main.o obj/test_functions.o obj/display_test_result.o obj/signal.o obj/sandbox.o obj/bench_functions.o \033[31m
\033[38;5;196m➤ \033[38;5;9m rm -f libft.so assets/libft.a assetslibtests assets/malloc.dylib \033[31m
\033[38;5;196m➤ \033[38;5;9m rm -f run_test \033[31m
\033[38;5;46m make -C ../libft \033[31m
make[1]: Entering directory `/home/username/libft'
gcc -Wall -Werror -Wextra -I./ -c  ft_bzero.c ft_isdigit.c ft_memset.c ft_strcmp.c ft_strlen.c ft_strnstr.c ft_toupper.c ft_isalnum.c ft_isprint.c ft_strcat.c ft_strcpy.c ft_strncat.c ft_strrchr.c ft_isalpha.c ft_memccpy.c ft_strchr.c ft_strdup.c ft_strncmp.c ft_strstr.c  ft_atoi.c ft_isascii.c ft_memcpy.c ft_strclr.c ft_strlcat.c ft_strncpy.c ft_tolower.c ft_memmove.c ft_memchr.c ft_memcmp.c
ar rc libft.a ft_bzero.o ft_isdigit.o ft_memset.o ft_strcmp.o ft_strlen.o ft_strnstr.o ft_toupper.o ft_isalnum.o ft_isprint.o ft_strcat.o ft_strcpy.o ft_strncat.o ft_strrchr.o ft_isalpha.o ft_memccpy.o ft_strchr.o ft_strdup.o ft_strncmp.o ft_strstr.o  ft_atoi.o ft_isascii.o ft_memcpy.o ft_strclr.o ft_strlcat.o ft_strncpy.o ft_tolower.o ft_memmove.o ft_memchr.o ft_memcmp.o
ranlib libft.a 
make[1]: Leaving directory `/home/username/libft'
\033[38;5;46m cp ../libft/libft.a assets/ \033[31m
make[1]: Entering directory `/home/username/libft'
make[1]: *** No rule to make target `so'.  Stop.
make[1]: Leaving directory `/home/username/libft'
make: *** [libft.so] Error 2
alelievr commented 7 years ago

In linux the usage is a bit more complicated, i'll add it to the readme. This unit-test needs the dynamic version of a libft to run, in macOS it's easy to turn a static library into a dynamic one, but it's not possible on linux unless obj file are compiled with -fPIC. So you need to add a rule called 'so' in the Makefile of your libft to create a dynamic library instead of static (your dynamic library must be called "libft.so").

nekitoss commented 7 years ago

i've added rule "so" to my Makefile, it looks like:

so:
    $(CC) -fPIC $(CFLAGS) $(SRC)
    gcc -shared -o libft.so $(BIN)

while trying to make re i think i found some small mistakes - there were ";" in rule SONAME:

$ git diff Makefile
...
@@ -80,7 +80,7 @@ RUN_COLOR             =       147
 ##    AUTO     ##
 #################

-SHELL          =       /bin/zsh
+SHELL          =       /bin/bash
 OBJ                    =       $(addprefix $(OBJDIR)/, $(addsuffix .o, $(basename $(SRC))))
 INCFLAG                =       $(addprefix -I,$(INCDIR))
 NORME          =       $(addsuffix /*.h,$(INCDIR)) $(addprefix $(SRCDIR)/,$(SRC))
@@ -141,12 +141,12 @@ $(SONAME):
 else
 $(SONAME):
        @make -C $(LIBFTDIR) so
-       @if [ -e $(LIBFTDIR)/libft.so ]; \
-               then; \
+       @if [ -e $(LIBFTDIR)/libft.so ];\
+               then\
                cp $(LIBFTDIR)/libft.so . ;\
-       else;\
-               echo Please provide a libft.so in the directory $(shell pwd); \
-       fi;
+       else\
+               echo Please provide a libft.so in the directory $(shell pwd);\
+       fi
 endif

 $(WRAPNAME): $(ASSETDIR)/wrapper.c
@@ -159,7 +159,7 @@ $(ASSETDIR)/$(ANAME):
        @rm -f $(SONAME)
        @$(call exec_color, "\033[38;5;$(LINK_COLOR_T)m", make -C "$(LIBFTDIR)")
        @$(call exec_color, "\033[38;5;$(LINK_COLOR_T)m", cp "$(LIBFTDIR)/libft.a" $(ASSETDIR)/)
-       
+
 #      Linking
 $(ASSETDIR)/$(NAME): $(OBJ)
        @$(call disp_title,Linking,$(LINK_COLOR_T));

when i deleted those i got next error (it doesn't like #include <bsd/string.h> in ./include/libft_test.h):


In file included from src/main.c:21:
./include/libft_test.h:31:12: fatal error: 'bsd/string.h' file not found
#  include <bsd/string.h>
           ^
1 error generated.
make: *** [obj/main.o] Error 1

I've searched google and found answer that i have to install package (for ubuntu): sudo apt-get install libbsd-dev

then i finally was able to run your superb tests =) so plz add also this info to description btw your tests are saving a lot of time for people in our cluster (in Kiyv)! but making us lazy =( and if i remember correctly we found some cases that might be added to this test - i'll write you if i find out that cases

also it is interesting if your test could run on 32-bit machine? when trying to compile it on my 32-bit Ubuntu Linux computer2name 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:31:42 UTC 2014 i686 i686 i686 GNU/Linux i get

./include/libft_test.h:98:2: error: size of anonymous bit-field (48 bits) exceeds size of its type (32 bits)
        long            :48;

if i try to set it to 32 i get


src/display_test_result.c:195:49: error: format specifies type 'unsigned long' but the argument has type 'unsigned long long' [-Werror,-Wformat]
                                current_fun_name, vdiff, speeder, opponent, TIME_DIFF_LIB, TIME_DIFF_SYS);
                                                                            ^~~~~~~~~~~~~
./include/libft_test.h:232:25: note: expanded from macro 'TIME_DIFF_LIB'
# define        TIME_DIFF_LIB           (g_time.mid - g_time.begin)
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
src/display_test_result.c:195:64: error: format specifies type 'unsigned long' but the argument has type 'unsigned long long' [-Werror,-Wformat]
                                current_fun_name, vdiff, speeder, opponent, TIME_DIFF_LIB, TIME_DIFF_SYS);
                                                                                           ^~~~~~~~~~~~~
./include/libft_test.h:231:25: note: expanded from macro 'TIME_DIFF_SYS'
# define        TIME_DIFF_SYS           (g_time.end - g_time.mid)
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
alelievr commented 7 years ago

thanks for your report, i've fixed the readme and removed the shell forced to zsh. i've also merged the linux and master branch and fixed the compilation for 32bit but i still don't know if it works on 32bit machines.

xmethula commented 5 years ago

Hi alelievr have been trying to configure your unit test on my Ubuntu Linux machine but I'm failing. Could you please provide a detailed process on how to use your unit test on Linux.

saladuit commented 3 years ago

I'm using Ubuntu 20.04, and i still got the same error.

uname -a Linux limitless-GE70-2PC 5.4.0-52-generic #57-Ubuntu SMP Thu Oct 15 10:57:00 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

gcc --version gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 Copyright (C) 2019 Free Software Foundation, Inc.

clang --version clang (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 Copyright (C) 2019 Free Software Foundation, Inc.

I've installed the right libraries, symlinked my gcc to clang, added the so rule, but it still gives the same error:

[ Building #0 ] ➤ gcc -O2 -funroll-loops -Werror -Wall -Wextra -I./include -o obj/src/main.o -c src/main.c In file included from src/main.c:21: src/main.c: In function ‘run_subtests’: ./include/libft_test.h:238:54: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result] 238 | # define RESET_DIFF lseek(g_diff_fd, 0, SEEK_SET); write(g_diff_fd, "\0", 1); | ^~~~~~~~~ src/main.c:147:3: note: in expansion of macro ‘RESET_DIFF’ 147 | RESET_DIFF; | ^~~~~~ src/main.c: In function ‘run_subbench’: ./include/libft_test.h:238:54: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result] 238 | # define RESET_DIFF lseek(g_diff_fd, 0, SEEK_SET); write(g_diff_fd, "\0", 1); | ^~~~~~~~~ src/main.c:172:3: note: in expansion of macro ‘RESET_DIFF’ 172 | RESET_DIFF; | ^~~~~~ src/main.c: In function ‘main’: src/main.c:282:2: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result] 282 | write(fd, &g_shared_mem, 8); | ^~~~~~~ In file included from src/main.c:21: ./include/libft_test.h:238:54: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result] 238 | # define RESET_DIFF lseek(g_diff_fd, 0, SEEK_SET); write(g_diff_fd, "\0", 1); | ^~~~~~~~~ src/main.c:289:2: note: in expansion of macro ‘RESET_DIFF’ 289 | RESET_DIFF; | ^~~~~~ cc1: all warnings being treated as errors make: [Makefile:193: obj/src/main.o] Error 1 [libft-unit-tests]$ make [ Building #0 ] ➤ clang -O2 -funroll-loops -Werror -Wall -Wextra -I./include -o obj/src/main.o -c src/main.c In file included from src/main.c:21: src/main.c: In function ‘run_subtests’: ./include/libft_test.h:238:54: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result] 238 | # define RESET_DIFF lseek(g_diff_fd, 0, SEEK_SET); write(g_diff_fd, "\0", 1); | ^~~~~~~~~ src/main.c:147:3: note: in expansion of macro ‘RESET_DIFF’ 147 | RESET_DIFF; | ^~~~~~ src/main.c: In function ‘run_subbench’: ./include/libft_test.h:238:54: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result] 238 | # define RESET_DIFF lseek(g_diff_fd, 0, SEEK_SET); write(g_diff_fd, "\0", 1); | ^~~~~~~~~ src/main.c:172:3: note: in expansion of macro ‘RESET_DIFF’ 172 | RESET_DIFF; | ^~~~~~ src/main.c: In function ‘main’: src/main.c:282:2: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result] 282 | write(fd, &g_shared_mem, 8); | ^~~~~~~ In file included from src/main.c:21: ./include/libft_test.h:238:54: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result] 238 | # define RESET_DIFF lseek(g_diff_fd, 0, SEEK_SET); write(g_diff_fd, "\0", 1); | ^~~~~~~~~ src/main.c:289:2: note: in expansion of macro ‘RESET_DIFF’ 289 | RESET_DIFF; | ^~~~~~ cc1: all warnings being treated as errors make: [Makefile:193: obj/src/main.o] Error 1