ignoring file lib.a, file was built for archive which is not the architecture being linked (x86_64)

前端 未结 3 1231
谎友^
谎友^ 2021-01-17 02:59

I\'m trying to code a printf clone. I\'ve built a library file called \"libftprintf.a\" but when I try to use it, I get the following error, on Mac OSX 10.8.5:



        
相关标签:
3条回答
  • 2021-01-17 03:43

    If you have fat architecture object files you must make sure that you pass the s flag to ar. Without it the linker will refuse to take archive files that contain fat architecture .o files. For example:

    $ ar rcs libprintf.a *.o
    

    You should then see a warning about creating a 'fat archive'. Don't worry about this, it means that ar won't be able to update the archive file, but the linker will be able to use it to link properly.

    0 讨论(0)
  • 2021-01-17 03:47

    Use libtool -static -o instead of ar.

    Static library link issue with Mac OS X: symbol(s) not found for architecture x86_64

    0 讨论(0)
  • 2021-01-17 03:49

    I've found a slightly dirty but working solution for now. I extract the libft/libft.a archive in a temporary directory. Link the new library with the extracted .o files and then remove the temporary directory.

    $(NAME): $(OBJ) $(HEADER)
        make -C libft
        mkdir libft_o && cd libft_o && ar -x ../libft/libft.a && cd ..
        $(AR) $(NAME) libft_o/*.o $(OBJ)
        rm -Rf libft_o
        ranlib $(NAME)
    

    The drawback being that if an object file from libft at some point has the same name than one from the printf files, it will overwrite things. But that's not likely to happen.

    0 讨论(0)
提交回复
热议问题