wjakob / nanogui

Minimalistic GUI library for OpenGL
Other
4.61k stars 604 forks source link

Error building with static lib option (STB_IMAGE_IMPLEMENTATION) #179

Open nathansizemore opened 7 years ago

nathansizemore commented 7 years ago
Debian GNU/Linux 8
kernel 3.16.0-4-amd64

$ gcc --version
gcc (GCC) 6.2.0

$ clang --version
clang version 3.9.1

When changing CMake option NANOGUI_BUILD_SHARED to OFF, the following errors are produced during compile time (-G "Unix Makefiles"). Same error, but thought I'd throw both outputs here anyway.

gcc

$ make
[ 25%] Built target glfw_objects
[ 29%] Built target bin2c
[ 82%] Built target nanogui-obj
[ 84%] Built target nanogui
[ 86%] Linking CXX executable example4
libnanogui.a(nanovg.c.o): In function `stbi_failure_reason':
nanovg.c:(.text+0x208e0): multiple definition of `stbi_failure_reason'
CMakeFiles/example4.dir/src/example4.cpp.o:example4.cpp:(.text+0x13c50): first defined here
libnanogui.a(nanovg.c.o): In function `stbi_image_free':
nanovg.c:(.text+0x208f0): multiple definition of `stbi_image_free'
CMakeFiles/example4.dir/src/example4.cpp.o:example4.cpp:(.text+0x13c60): first defined here
libnanogui.a(nanovg.c.o): In function `stbi_set_flip_vertically_on_load':
nanovg.c:(.text+0x20900): multiple definition of `stbi_set_flip_vertically_on_load'
CMakeFiles/example4.dir/src/example4.cpp.o:example4.cpp:(.text+0x13c70): first defined here
libnanogui.a(nanovg.c.o): In function `stbi_is_hdr_from_memory':
nanovg.c:(.text+0x20910): multiple definition of `stbi_is_hdr_from_memory'
CMakeFiles/example4.dir/src/example4.cpp.o:example4.cpp:(.text+0x13c80): first defined here
libnanogui.a(nanovg.c.o): In function `stbi_is_hdr':
nanovg.c:(.text+0x20a30): multiple definition of `stbi_is_hdr'

clang

$ make
[ 25%] Built target glfw_objects
[ 29%] Built target bin2c
[ 82%] Built target nanogui-obj
[ 84%] Built target nanogui
[ 86%] Linking CXX executable example4
libnanogui.a(nanovg.c.o): In function `stbi_convert_iphone_png_to_rgb':
/home/nathan/development/nanogui/ext/nanovg/src/nanovg.c:(.text+0xd580): multiple definition of `stbi_convert_iphone_png_to_rgb'
CMakeFiles/example4.dir/src/example4.cpp.o:/home/nathan/development/nanogui/src/example4.cpp:(.text+0x3760): first defined here
libnanogui.a(nanovg.c.o): In function `stbi_failure_reason':
/home/nathan/development/nanogui/ext/nanovg/src/nanovg.c:(.text+0x9e20): multiple definition of `stbi_failure_reason'
CMakeFiles/example4.dir/src/example4.cpp.o:/home/nathan/development/nanogui/src/example4.cpp:(.text+0x0): first defined here
libnanogui.a(nanovg.c.o): In function `stbi_hdr_to_ldr_gamma':
/home/nathan/development/nanogui/ext/nanovg/src/nanovg.c:(.text+0xc250): multiple definition of `stbi_hdr_to_ldr_gamma'
CMakeFiles/example4.dir/src/example4.cpp.o:/home/nathan/development/nanogui/src/example4.cpp:(.text+0x2430): first defined here
libnanogui.a(nanovg.c.o): In function `stbi_hdr_to_ldr_scale':
/home/nathan/development/nanogui/ext/nanovg/src/nanovg.c:(.text+0xc270): multiple definition of `stbi_hdr_to_ldr_scale'
CMakeFiles/example4.dir/src/example4.cpp.o:/home/nathan/development/nanogui/src/example4.cpp:(.text+0x2450): first defined here
libnanogui.a(nanovg.c.o): In function `stbi_image_free':
/home/nathan/development/nanogui/ext/nanovg/src/nanovg.c:(.text+0x9e30): multiple definition of `stbi_image_free'
CMakeFiles/example4.dir/src/example4.cpp.o:/home/nathan/development/nanogui/src/example4.cpp:(.text+0x10): first defined here
libnanogui.a(nanovg.c.o): In function `stbi_info':
/home/nathan/development/nanogui/ext/nanovg/src/nanovg.c:(.text+0xd700): multiple definition of `stbi_info'
CMakeFiles/example4.dir/src/example4.cpp.o:/home/nathan/development/nanogui/src/example4.cpp:(.text+0x38e0): first defined here
austensatterlee commented 7 years ago

Ran into this today using msvc on windows as well. STB_IMAGE_IMPLEMENTATION is already defined in nanovg.c, so removing the #define STB_IMAGE_IMPLEMENTATION in my own code seemed to fix the problem.

nathansizemore commented 7 years ago

Ah yes, removing that from example4 and example1 did the trick.