RandyGaul / cute_headers

Collection of cross-platform one-file C/C++ libraries with no dependencies, primarily used for games
4.24k stars 264 forks source link

cute_math.h: GCC 12 ignores always_line and select any leading to multiple definition linker errors #321

Closed legends2k closed 1 year ago

legends2k commented 1 year ago

I've main.cpp and scene.cpp where cute_math.h is included. I define CUTE_MATH_IMPLEMENTATION in neither (since I don't need the larger functions). Compilation succeeds but linking fails with numerous warnings about attributes selectany and always_line ignored. Understandably linker errors ensure when linking. Sample errors:

Nila/build/cute_math.h:203:45: warning: ‘selectany’ attribute directive ignored [-Wattributes]
  203 | CUTE_MATH_SELECTANY cute_math_const_integer cute_math_mask_sign = { 0x80000000, 0x80000000, 0x80000000, 0x80000000 };
      |                                             ^~~~~~~~~~~~~~~~~~~

Nila/build/cute_math.h:645:36: warning: ‘always_inline’ function might not be inlinable [-Wattributes]
  645 | CUTE_MATH_INLINE q4 CUTE_MATH_CALL norm(q4 q)
      |                                    ^~~~

/usr/bin/c++ -g  CMakeFiles/nila.dir/src/main.cpp.o CMakeFiles/nila.dir/src/scene.cpp.o -o nila  libtigr.a  /usr/lib/libGLU.so  /usr/lib/libGLX.so  /usr/lib/libOpenGL.so  /usr/lib/libX11.so && :
/usr/bin/ld: CMakeFiles/nila.dir/src/scene.cpp.o:(.rodata+0x0): multiple definition of `cute::cute_math_mask_sign'; CMakeFiles/nila.dir/src/main.cpp.o:(.rodata+0x0): first defined here
/usr/bin/ld: CMakeFiles/nila.dir/src/scene.cpp.o:(.rodata+0x20): multiple definition of `cute::cute_math_mask_basis'; CMakeFiles/nila.dir/src/main.cpp.o:(.rodata+0x20): first defined here
/usr/bin/ld: CMakeFiles/nila.dir/src/scene.cpp.o:(.bss+0x0): multiple definition of `cute::identity_m3'; CMakeFiles/nila.dir/src/main.cpp.o:(.bss+0x0): first defined here

Relevant StackOverflow post: warning: always_inline function might not be inlinable [-Wattributes]

legends2k commented 1 year ago

Relevant issues #50, #17, #18.

RandyGaul commented 1 year ago

Any suggested solution?

legends2k commented 1 year ago

@RandyGaul For always_inline #18 already introduced the fix -- adding inline keyword along with the attribute. Looks like the fix was overwritten over time. Not sure of selectany though.

RandyGaul commented 1 year ago

Okay cool, could you make a PR for this?

legends2k commented 1 year ago

Okay cool, could you make a PR for this?

Done!

RandyGaul commented 1 year ago

Looks good!