Linking error when building mupdf with MinGW-w64 - linker
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?
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"
I had this same issue (multiple definitions of various symbols) using Artifex's stand-alone jbig2dec v0.19 library with MuPDF v1.21 and building with MinGW-w64. What solved it for me was the comment Tamir Evan made about the patch that MSYS2 made to jbig2dec's os_types.h file. This is my os_types.h which fixed the issue for me (the __CRT__NO_INLINE definition is critical). No special linking flags (like -Wl,--allow-multiple-definition) needed.
/* os_types.h */
#ifndef _JBIG2_OS_TYPES_H
#define _JBIG2_OS_TYPES_H
#include <stdint.h>
#if (defined(__MINGW32__) || defined(__MINGW64__))
#define __CRT__NO_INLINE 1
#endif
#endif /* _JBIG2_OS_TYPES_H */
Related
Resolve 'undefined reference' to a global external array variable
I have a header constants.h file, with the following declarations of an array variable: extern storageCommandData storageCommands[]; The type of the array is defined elsewhere, and is not relevant to the question. In another source file (.c) I initialized the array like so: #include "constants.h" storageCommandData storageCommands[STORAGE_COMMAND_NUM] = { /*storageCommandData intilazation follows the following template: {commandName, storageSize}*/ {".db", 1}, {".dw", 4}, {".dh", 2}, {".asciz", 0}, }; I tried to use these arrays in another source file (a different one than the one I define the arrays in), by including constants.h. However, when I try to use the variable storageCommands I get the following error message: undefined reference to `storageCommands' How do I fix the error?
Using extern means that you are using a variable that is declared in another translation unit (i.e. basically a source file and the headers it includes). It is the linker's task to relate the extern-specified variable name to its actual declaration. If the linker cannot find the latter, it will report an "undefined reference". As already pointed out in the comments, the most common cause of this error is that the source file containing the actual declaration was not compiled or linked.
Multiple Declarations of [variable name]
I am working on a header file that does a couple of functions for me. I include the header file in two seperate files, the c file and the main file. I use #ifndef and #def but it looks like it still gets compiled twice, because during the linking process I get serveral multiple declarations of ... errors. PLL header file #ifndef PLL_HEADER #define PLL_HEADER /******************************************************************** * includes ********************************************************************/ #include "board.h" #include "pin_mux.h" #include "clock_config.h" #include "PITDriver.h" // Some more stuff #endif Here is the relevant log data [compiling stuff] Building target: PLL Function.axf Invoking: MCU Linker [other linker stuff] ./source/main.o:C:\Users\mailn\Desktop\Work\Sparton\MCUXPresso Workstation\PLL Function\Debug/../source/PLL.h:45: multiple definition of `accumulateVal' ./source/PLL.o:C:\Users\mailn\Desktop\Work\Sparton\MCUXPresso Workstation\PLL Function\Debug/../source/PLL.h:45: first defined here ./source/main.o:C:\Users\mailn\Desktop\Work\Sparton\MCUXPresso Workstation\PLL Function\Debug/../source/PLL.h:46: multiple definition of `getValOne' ./source/PLL.o:C:\Users\mailn\Desktop\Work\Sparton\MCUXPresso Workstation\PLL Function\Debug/../source/PLL.h:46: first defined here ./source/main.o:C:\Users\mailn\Desktop\Work\Sparton\MCUXPresso Workstation\PLL Function\Debug/../source/PLL.h:47: multiple definition of `getValTwo' ./source/PLL.o:C:\Users\mailn\Desktop\Work\Sparton\MCUXPresso Workstation\PLL Function\Debug/../source/PLL.h:47: first defined here ./source/main.o:C:\Users\mailn\Desktop\Work\Sparton\MCUXPresso Workstation\PLL Function\Debug/../source/PLL.h:48: multiple definition of `countTo' ./source/PLL.o:C:\Users\mailn\Desktop\Work\Sparton\MCUXPresso Workstation\PLL Function\Debug/../source/PLL.h:48: first defined here ./source/main.o:C:\Users\mailn\Desktop\Work\Sparton\MCUXPresso Workstation\PLL Function\Debug/../source/PLL.h:49: multiple definition of `runUntil' ./source/PLL.o:C:\Users\mailn\Desktop\Work\Sparton\MCUXPresso Workstation\PLL Function\Debug/../source/PLL.h:49: first defined here ./source/main.o:C:\Users\mailn\Desktop\Work\Sparton\MCUXPresso Workstation\PLL Function\Debug/../source/PLL.h:50: multiple definition of `currentValue' ./source/PLL.o:C:\Users\mailn\Desktop\Work\Sparton\MCUXPresso Workstation\PLL Function\Debug/../source/PLL.h:50: first defined here collect2.exe: error: ld returned 1 exit status make: *** [makefile:39: PLL Function.axf] Error 1
Correction made according to the comment of #Peter In C you can only put variable definitions in a header if it is only included in one compilation unit. You seem to have two compilation unit : one that compiles your PLL.h and PLL.c to create PLL.o one that compiles your main.c and PLL.h to create main.o Both of your objects files contain the variables that you have defined in PLL.h and therefore when you hit the linker it throws an error because the variables have been declared twice (once in each object file). To correct this error you can either change the way you compile to merge your two compilation unit. Or (if you use an IDE that handles automatically your compilation) you can apply the following changes to avoid defining the variable in your header. In the header : (change the definition to a declaration) extern int x; In a source file : (define the variable) int x;
Multiple definition of lots of function in linux kernel 2.4.32 compiling
I am going to compile the linux kernel 2.4.32 in my x86_64 system. make dep is ok but make bzImage stop after showing lots of link error like these: ld -m elf_x86_64 -e stext -r -o kernel.o sched.o dma.o fork.o exec_domain.o panic.o printk.o module.o exit.o itimer.o info.o time.o softirq.o resource.o sysctl.o acct.o capability.o ptrace.o timer.o user.o signal.o sys.o kmod.o context.o ksyms.o pm.o dma.o: In function `set_64bit': dma.c:(.text+0x0): multiple definition of `set_64bit' sched.o:sched.c:(.text+0x1b): first defined here dma.o: In function `get_order': dma.c:(.text+0x4): multiple definition of `get_order' sched.o:sched.c:(.text+0x0): first defined here dma.o: In function `read_lock': dma.c:(.text+0x1a): multiple definition of `read_lock' sched.o:sched.c:(.text+0x9c): first defined here dma.o: In function `cpuid': dma.c:(.text+0xc9): multiple definition of `cpuid' sched.o:sched.c:(.text+0x24): first defined here dma.o: In function `cpuid_eax': dma.c:(.text+0xe1): multiple definition of `cpuid_eax' sched.o:sched.c:(.text+0x41): first defined here dma.o: In function `cpuid_ebx': dma.c:(.text+0xe8): multiple definition of `cpuid_ebx' sched.o:sched.c:(.text+0x4d): first defined here dma.o: In function `cpuid_ecx': dma.c:(.text+0xf1): multiple definition of `cpuid_ecx' sched.o:sched.c:(.text+0x5b): first defined here dma.o: In function `cpuid_edx': dma.c:(.text+0xfa): multiple definition of `cpuid_edx' sched.o:sched.c:(.text+0x69): first defined here dma.o: In function `thread_saved_pc': dma.c:(.text+0x103): multiple definition of `thread_saved_pc' sched.o:sched.c:(.text+0x77): first defined here dma.o: In function `rep_nop': dma.c:(.text+0x10c): multiple definition of `rep_nop' sched.o:sched.c:(.text+0x85): first defined here dma.o: In function `sync_core': dma.c:(.text+0x10f): multiple definition of `sync_core' sched.o:sched.c:(.text+0x8d): first defined here in the kernel2.4.32/include directory there is lots of asm directories each belonging to an specific architecture (e.g. asm-i386, asm-x86_64, asm-a64) and there is a single asm directory which is linked to asm-x86_64 directory (because of my system architecture) when i remove a function with multiple definition (like set_64bit in error list) from one of these two directories asm and asm-x86_64 the error will disappear. Is there any problem with makefile or config file? why these functions compile multiple times??! pleas help me...
The problem is from a misprint functions' definition in header file as #Tsyvarev had been correctly mentioned. These problematic functions definition must be changed from extern inline to static inline. Also the definition of functions about I/O, like inb, inw, inl, outb, outw, outl.... must be changed in linux2.4.32/include/asm/io.h file where these functions is defined as macros with extern keyword!
Linker option for multiple definition of function
Is there any Linker option, which enforces error for multiple definition of a function. I am using ARM GCC mingw. I am facing problem where if I am using Guard in header file(say A.h) like this #ifndef H_H_ #define H_H_ and declare function definition inside it Linker is not giving error for Multiple definitions of that function in different .C files which includes above A.h file
C/C++ verbose compiling error, multiple definitions
I'm not much of a C/C++ programmer myself, but I've been tasked with building a Deconvolution program used in my lab. Here is the complaint I've been getting: [ 10%] Building (Device) NVCC /home/chris/Desktop/Clarity-1.0/src/WienerDeconvolveGPU.cu: /home/chris/Desktop/Clarbuild/src/cuda/src/WienerDeconvolveGPU.cu_Clarity_generated.cpp [ 13%] Building CXX object CMakeFiles/Clarity.dir/src/WienerDeconvolve.o /home/chris/Desktop/Clarity-1.0/src/WienerDeconvolve.cxx: In function ‘ClarityResult_t Clarity_WienerDeconvolve(float*, Clarity_Dim3, float*, Clarity_Dim3, float*, float)’: /home/chris/Desktop/Clarity-1.0/src/WienerDeconvolve.cxx:211: error: ‘malloc’ was not declared in this scope /home/chris/Desktop/Clarity-1.0/src/WienerDeconvolve.cxx:246: error: ‘free’ was not declared in this scope make[2]: *** [CMakeFiles/Clarity.dir/src/WienerDeconvolve.o] Error 1 make[1]: *** [CMakeFiles/Clarity.dir/all] Error 2 make: *** [all] Error 2 The normal solution I've found is to insert #include cstlib in the code, WienerDeconvolve.cxx, but when I do that, this happens: [ 2%] Building CXX object CMakeFiles/Clarity.dir/src/WienerDeconvolve.o Linking CXX static library libClarity.a [ 89%] Built target Clarity Linking CXX executable ConvolutionTest [ 92%] Built target ConvolutionTest Linking CXX executable JansenVanCittertTest [ 94%] Built target JansenVanCittertTest Linking CXX executable MaximumLikelihoodTest [ 97%] Built target MaximumLikelihoodTest Linking CXX executable WienerFilterTest ../../libClarity.a(WienerDeconvolve.o): In function `ComplexConjugate(float2)': WienerDeconvolve.cxx:(.text+0x2a0): multiple definition of `ComplexConjugate(float2)' ../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x0): first defined here ../../libClarity.a(WienerDeconvolve.o): In function `ComplexAdd(float2, float2)': WienerDeconvolve.cxx:(.text+0x2c6): multiple definition of `ComplexAdd(float2, float2)' ../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x24): first defined here ../../libClarity.a(WienerDeconvolve.o): In function `ComplexMultiply(float2, float2)': WienerDeconvolve.cxx:(.text+0x300): multiple definition of `ComplexMultiply(float2, float2)' ../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x54): first defined here ../../libClarity.a(WienerDeconvolve.o): In function `ComplexScale(float2, float)': WienerDeconvolve.cxx:(.text+0x34e): multiple definition of `ComplexScale(float2, float)' ../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x84): first defined here ../../libClarity.a(WienerDeconvolve.o): In function `ComplexMultiplyAndScale(float2, float2, float)': WienerDeconvolve.cxx:(.text+0x378): multiple definition of `ComplexMultiplyAndScale(float2, float2, float)' ../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0xa8): first defined here ../../libClarity.a(WienerDeconvolve.o): In function `ComplexMagnitudeSquared(float2)': WienerDeconvolve.cxx:(.text+0x3ed): multiple definition of `ComplexMagnitudeSquared(float2)' ../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0xd8): first defined here ../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexConjugate(float2)': WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0x0): multiple definition of `ComplexConjugate(float2)' ../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x0): first defined here ../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexAdd(float2, float2)': WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0x24): multiple definition of `ComplexAdd(float2, float2)' ../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x24): first defined here ../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexMultiply(float2, float2)': WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0x54): multiple definition of `ComplexMultiply(float2, float2)' ../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x54): first defined here ../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexScale(float2, float)': WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0x84): multiple definition of `ComplexScale(float2, float)' ../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0x84): first defined here ../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexMultiplyAndScale(float2, float2, float)': WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0xa8): multiple definition of `ComplexMultiplyAndScale(float2, float2, float)' ../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0xa8): first defined here ../../libClarity.a(WienerDeconvolveGPU.cu_Clarity_generated.o): In function `ComplexMagnitudeSquared(float2)': WienerDeconvolveGPU.cu_Clarity_generated.cpp:(.text+0xd8): multiple definition of `ComplexMagnitudeSquared(float2)' ../../libClarity.a(FFTGPU.cu_Clarity_generated.o):FFTGPU.cu_Clarity_generated.cpp:(.text+0xd8): first defined here collect2: ld returned 1 exit status make[2]: *** [tests/WienerFilterTest/WienerFilterTest] Error 1 make[1]: *** [tests/WienerFilterTest/CMakeFiles/WienerFilterTest.dir/all] Error 2 make: *** [all] Error 2 This is a pretty large project, and thus these are some intimidating errors for me. Does anyone have any idea what the problem could be? Many people have compiled this, and it's been tested on RedHat. After messing with it a few days I'm out of ideas, but I'll be happy to provide any information that might help.
Looking at the error messages posted, I would say that the #include<cstdlib> is unrelated to the second set of errors. Including cstdlib solved some compilation errors, allowing the compilation stage to complete and the linking stage to start. The second set of errors is raised during the link stage because some functions have been defined in more than one compilation unit. The error messages indicate that the files with the names WienerDeconvolve.cxx, WienerDeconvolveGPU.cu_Clarity_generated.cpp, and FFTGPU.cu_Clarity_generated.cpp all contain definitions for functions with the same signature: ComplexConjugate(float2), ComplexAdd(float2, float2), etc. Bascially, when the linker finds multiple functions with the same signature, it is unsure which one to use and generates these errors. There are a number of reasons that these errors could occur, such as: The intent was for the functions to be local to the compilation unit, but it was forgotten to declare them as static or to place them in an anonymous namespace. The functions were defined in a header file that was included by multiple source files. See this post for more information: Link error with really simple functions C++ on .h file What you will need to do is look through your code to find the location(s) where these multiply defined functions are being defined to determine exactly how they are being defined more than once. That information will let you determine the solution to the problem.
The normal solution I've found is to insert #include cstlib in the code, WienerDeconvolve.cxx That part scares me. Weird wording aside, are you #includeing .cxx files? The only other way you get that error is if you have function definitions in your header, as opposed to only declarations. Well, you could also be linking an object multiple times I guess, but I haven't yet seen someone do that :)