linkermingwmupdfjbig2

Linking error when building mupdf with MinGW-w64


I tried to build mupdf libs with MinGW-w64. Compiling and ar operations were finished, but when linking the exec file, it reported errors like that

build/mingw64-cross/release/libmupdf-third.a(jbig2_symbol_dict.o):jbig2_symbol_dict.c:(.text$_Exit+0x0): multiple definition of `_Exit'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$_Exit+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_symbol_dict.o):jbig2_symbol_dict.c:(.text$llabs+0x0): multiple definition of `llabs'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$llabs+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_symbol_dict.o):jbig2_symbol_dict.c:(.text$atoll+0x0): multiple definition of `atoll'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$atoll+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_symbol_dict.o):jbig2_symbol_dict.c:(.text$lltoa+0x0): multiple definition of `lltoa'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$lltoa+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_symbol_dict.o):jbig2_symbol_dict.c:(.text$ulltoa+0x0): multiple definition of `ulltoa'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$ulltoa+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_symbol_dict.o):jbig2_symbol_dict.c:(.text$wtoll+0x0): multiple definition of `wtoll'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$wtoll+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_symbol_dict.o):jbig2_symbol_dict.c:(.text$lltow+0x0): multiple definition of `lltow'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$lltow+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_symbol_dict.o):jbig2_symbol_dict.c:(.text$ulltow+0x0): multiple definition of `ulltow'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$ulltow+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_text.o):jbig2_text.c:(.text$_Exit+0x0): multiple definition of `_Exit'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$_Exit+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_text.o):jbig2_text.c:(.text$llabs+0x0): multiple definition of `llabs'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$llabs+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_text.o):jbig2_text.c:(.text$atoll+0x0): multiple definition of `atoll'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$atoll+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_text.o):jbig2_text.c:(.text$lltoa+0x0): multiple definition of `lltoa'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$lltoa+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_text.o):jbig2_text.c:(.text$ulltoa+0x0): multiple definition of `ulltoa'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$ulltoa+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_text.o):jbig2_text.c:(.text$wtoll+0x0): multiple definition of `wtoll'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$wtoll+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_text.o):jbig2_text.c:(.text$lltow+0x0): multiple definition of `lltow'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$lltow+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_text.o):jbig2_text.c:(.text$ulltow+0x0): multiple definition of `ulltow'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$ulltow+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_arith_iaid.o):jbig2_arith_iaid.c:(.text$_Exit+0x0): multiple definition of `_Exit'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$_Exit+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_arith_iaid.o):jbig2_arith_iaid.c:(.text$llabs+0x0): multiple definition of `llabs'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$llabs+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_arith_iaid.o):jbig2_arith_iaid.c:(.text$atoll+0x0): multiple definition of `atoll'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$atoll+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_arith_iaid.o):jbig2_arith_iaid.c:(.text$lltoa+0x0): multiple definition of `lltoa'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$lltoa+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_arith_iaid.o):jbig2_arith_iaid.c:(.text$ulltoa+0x0): multiple definition of `ulltoa'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$ulltoa+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_arith_iaid.o):jbig2_arith_iaid.c:(.text$wtoll+0x0): multiple definition of `wtoll'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$wtoll+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_arith_iaid.o):jbig2_arith_iaid.c:(.text$lltow+0x0): multiple definition of `lltow'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$lltow+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_arith_iaid.o):jbig2_arith_iaid.c:(.text$ulltow+0x0): multiple definition of `ulltow'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$ulltow+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_arith_int.o):jbig2_arith_int.c:(.text$_Exit+0x0): multiple definition of `_Exit'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$_Exit+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_arith_int.o):jbig2_arith_int.c:(.text$llabs+0x0): multiple definition of `llabs'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$llabs+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_arith_int.o):jbig2_arith_int.c:(.text$atoll+0x0): multiple definition of `atoll'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$atoll+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_arith_int.o):jbig2_arith_int.c:(.text$lltoa+0x0): multiple definition of `lltoa'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$lltoa+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_arith_int.o):jbig2_arith_int.c:(.text$ulltoa+0x0): multiple definition of `ulltoa'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$ulltoa+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_arith_int.o):jbig2_arith_int.c:(.text$wtoll+0x0): multiple definition of `wtoll'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$wtoll+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_arith_int.o):jbig2_arith_int.c:(.text$lltow+0x0): multiple definition of `lltow'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$lltow+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_arith_int.o):jbig2_arith_int.c:(.text$ulltow+0x0): multiple definition of `ulltow'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$ulltow+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_generic.o):jbig2_generic.c:(.text$_Exit+0x0): multiple definition of `_Exit'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$_Exit+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_generic.o):jbig2_generic.c:(.text$llabs+0x0): multiple definition of `llabs'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$llabs+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_generic.o):jbig2_generic.c:(.text$atoll+0x0): multiple definition of `atoll'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$atoll+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_generic.o):jbig2_generic.c:(.text$lltoa+0x0): multiple definition of `lltoa'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$lltoa+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_generic.o):jbig2_generic.c:(.text$ulltoa+0x0): multiple definition of `ulltoa'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$ulltoa+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_generic.o):jbig2_generic.c:(.text$wtoll+0x0): multiple definition of `wtoll'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$wtoll+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_generic.o):jbig2_generic.c:(.text$lltow+0x0): multiple definition of `lltow'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$lltow+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_generic.o):jbig2_generic.c:(.text$ulltow+0x0): multiple definition of `ulltow'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$ulltow+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_halftone.o):jbig2_halftone.c:(.text$_Exit+0x0): multiple definition of `_Exit'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$_Exit+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_halftone.o):jbig2_halftone.c:(.text$llabs+0x0): multiple definition of `llabs'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$llabs+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_halftone.o):jbig2_halftone.c:(.text$atoll+0x0): multiple definition of `atoll'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$atoll+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_halftone.o):jbig2_halftone.c:(.text$lltoa+0x0): multiple definition of `lltoa'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$lltoa+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_halftone.o):jbig2_halftone.c:(.text$ulltoa+0x0): multiple definition of `ulltoa'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$ulltoa+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_halftone.o):jbig2_halftone.c:(.text$wtoll+0x0): multiple definition of `wtoll'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$wtoll+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_halftone.o):jbig2_halftone.c:(.text$lltow+0x0): multiple definition of `lltow'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$lltow+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_halftone.o):jbig2_halftone.c:(.text$ulltow+0x0): multiple definition of `ulltow'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$ulltow+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_mmr.o):jbig2_mmr.c:(.text$llabs+0x0): multiple definition of `llabs'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$llabs+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_mmr.o):jbig2_mmr.c:(.text$atoll+0x0): multiple definition of `atoll'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$atoll+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_mmr.o):jbig2_mmr.c:(.text$lltoa+0x0): multiple definition of `lltoa'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$lltoa+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_mmr.o):jbig2_mmr.c:(.text$ulltoa+0x0): multiple definition of `ulltoa'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$ulltoa+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_mmr.o):jbig2_mmr.c:(.text$wtoll+0x0): multiple definition of `wtoll'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$wtoll+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_mmr.o):jbig2_mmr.c:(.text$lltow+0x0): multiple definition of `lltow'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$lltow+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_mmr.o):jbig2_mmr.c:(.text$ulltow+0x0): multiple definition of `ulltow'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$ulltow+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_refinement.o):jbig2_refinement.c:(.text$_Exit+0x0): multiple definition of `_Exit'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$_Exit+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_refinement.o):jbig2_refinement.c:(.text$llabs+0x0): multiple definition of `llabs'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$llabs+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_refinement.o):jbig2_refinement.c:(.text$atoll+0x0): multiple definition of `atoll'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$atoll+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_refinement.o):jbig2_refinement.c:(.text$lltoa+0x0): multiple definition of `lltoa'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$lltoa+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_refinement.o):jbig2_refinement.c:(.text$ulltoa+0x0): multiple definition of `ulltoa'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$ulltoa+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_refinement.o):jbig2_refinement.c:(.text$wtoll+0x0): multiple definition of `wtoll'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$wtoll+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_refinement.o):jbig2_refinement.c:(.text$lltow+0x0): multiple definition of `lltow'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$lltow+0x0): first defined here
build/mingw64-cross/release/libmupdf-third.a(jbig2_refinement.o):jbig2_refinement.c:(.text$ulltow+0x0): multiple definition of `ulltow'
build/mingw64-cross/release/libmupdf-third.a(jbig2_segment.o):jbig2_segment.c:(.text$ulltow+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
mingw32-make: *** [Makefile:247: build/mingw64-cross/release/mutool] Error 1

Those errors were all about jbig2dec library. It seemes that those programs defined symbols like _Exit multiple times, but in source files, I didn't fond any use of such symbols. I used nm command to analyse the jbig2_segment.o file, then I found that

...
0000000000000000 t .text
0000000000000000 t .text$_Exit
0000000000000000 t .text$atoll
0000000000000000 t .text$jbig2_find_segment
0000000000000000 t .text$jbig2_free_segment
0000000000000000 t .text$jbig2_get_region_segment_info
0000000000000000 t .text$jbig2_parse_segment
0000000000000000 t .text$jbig2_parse_segment_header
0000000000000000 t .text$llabs
0000000000000000 t .text$lltoa
0000000000000000 t .text$lltow
0000000000000000 t .text$ulltoa
0000000000000000 t .text$ulltow
0000000000000000 t .text$wtoll
...

It show that symbols like _Exit and atoll were really defined, but there were no such symbols in the program source file. Except jbig2_xxx.o, other .o files had no such symbols.

Then, I used linux to build the same project, and it passed. So what caused this problem? how could I fix it?


Solution

  • A workaround could be to use linker flag -Wl,--allow-multiple-definition, for example with make LDFLAGS="-Wl,--allow-multiple-definition".

    Personally I build MuPDF with MinGW-w64 without any of the suplied third party code. Instead I have all the dependancy libraries already compiled on my system and the build MuPDF with:

    make NOX11=yes CC=gcc USE_SYSTEM_LIBS=yes SYS_FREETYPE_LIBS=-lfreetype CFLAGS="$(pkg-config --cflags libopenjp2) -I$(pwd)/include -I$(pwd)/fitz -I$(pwd)/pdf" SYS_GUMBO_LIBS="-lgumbo" LDFLAGS="-Wl,--as-needed -lfreetype -ljbig2dec -ljpeg -lopenjp2 -lz"