nevat / abbayedesmorts-gpl

l'Abbaye des Morts - ported to Linux, Pandora, GCW0, Wii and PSP
GNU General Public License v3.0
73 stars 16 forks source link

Multiple definitions of renderer #13

Closed jmdejong closed 4 years ago

jmdejong commented 4 years ago

When trying to compile with make I get a linker error that there are multiple definitions of renderer:

Here is the output I get. I have added the -g flag to the compilation command in the makefile to get a bit better output. For the rest this is from the latest master branch.

$ make
cc -g -O2 -finline-functions -funswitch-loops -fgcse-after-reload -fpredictive-commoning -ftree-vectorize -Wno-unused-result `sdl2-config --cflags` -DDATADIR="\"/usr/share/abbayev2\"" -Wl,-z,relro src/drawing.c src/ending.c src/enemies.c src/game.c src/gameover.c src/history.c src/jean.c src/loading.c src/main.c src/startscreen.c -o abbayev2 `sdl2-config --libs` -lSDL2_image -lSDL2_mixer -lm
/usr/bin/ld: /tmp/cc4lAScW.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: multiple definition of `renderer'; /tmp/ccuW3dcY.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: first defined here
/usr/bin/ld: /tmp/ccv8aFQY.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: multiple definition of `renderer'; /tmp/ccuW3dcY.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: first defined here
/usr/bin/ld: /tmp/cc9UJSBX.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: multiple definition of `renderer'; /tmp/ccuW3dcY.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: first defined here
/usr/bin/ld: /tmp/cc5y1eXV.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: multiple definition of `renderer'; /tmp/ccuW3dcY.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: first defined here
/usr/bin/ld: /tmp/ccYd4m3V.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: multiple definition of `renderer'; /tmp/ccuW3dcY.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: first defined here
/usr/bin/ld: /tmp/ccYzawFY.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: multiple definition of `renderer'; /tmp/ccuW3dcY.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: first defined here
/usr/bin/ld: /tmp/cctbASdZ.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: multiple definition of `renderer'; /tmp/ccuW3dcY.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: first defined here
/usr/bin/ld: /tmp/ccHShYBY.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: multiple definition of `renderer'; /tmp/ccuW3dcY.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: first defined here
/usr/bin/ld: /tmp/ccWJDZ4V.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: multiple definition of `renderer'; /tmp/ccuW3dcY.o:/data/programming/others/abbayedesmorts-gpl/src/base.h:17: first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:42: abbayev2] Error 1

I am using gcc 10.2.0 I am not the only one who has this problem

I've been tinkering around a bit and found out that adding the extern keyword to the offending line, and then adding the definition in the main file seems to solve this issue. So this means changing the declaration in base.h to extern SDL_Renderer *renderer; and adding SDL_Renderer *renderer; in main.c between the include and the main function.

However, when solving the problem this way the program only shows a black screen when I try to run it. I don't know if that is related to the solution or an unrelated problem.

Edit: The black screen was because I did not install the game yet, so I didn't have the assets. Running make install solved that.

When compiling with gcc 9.3.0 the linker error does not occur and the game runs fine.