tgx icon indicating copy to clipboard operation
tgx copied to clipboard

Linker error in Debug mode

Open liux-pro opened this issue 1 year ago • 2 comments

Hi! I am trying to build tgx example buddhaOnCPU, in release mode , everything works fine.
But when I change to debug mode with cmake -DCMAKE_BUILD_TYPE=Debug .., a linker error shows up.

root@aefb89601979:~/tgx/examples/CPU/buddhaOnCPU/build# cmake -DCMAKE_BUILD_TYPE=Debug ..
-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found X11: /usr/include
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Configuring done
-- Generating done
-- Build files have been written to: /root/tgx/examples/CPU/buddhaOnCPU/build
root@aefb89601979:~/tgx/examples/CPU/buddhaOnCPU/build# make
[ 10%] Building CXX object CMakeFiles/buddhaOnCPU.dir/buddhaOnCPU.cpp.o
[ 20%] Building CXX object CMakeFiles/buddhaOnCPU.dir/root/tgx/src/Color.cpp.o
[ 30%] Building CXX object CMakeFiles/buddhaOnCPU.dir/root/tgx/src/Fonts.cpp.o
[ 40%] Building CXX object CMakeFiles/buddhaOnCPU.dir/root/tgx/src/Renderer3D.cpp.o
[ 50%] Building CXX object CMakeFiles/buddhaOnCPU.dir/root/tgx/src/font_tgx_Arial.cpp.o
[ 60%] Building CXX object CMakeFiles/buddhaOnCPU.dir/root/tgx/src/font_tgx_Arial_Bold.cpp.o
[ 70%] Building CXX object CMakeFiles/buddhaOnCPU.dir/root/tgx/src/font_tgx_OpenSans.cpp.o
[ 80%] Building CXX object CMakeFiles/buddhaOnCPU.dir/root/tgx/src/font_tgx_OpenSans_Bold.cpp.o
[ 90%] Building CXX object CMakeFiles/buddhaOnCPU.dir/root/tgx/src/font_tgx_OpenSans_Italic.cpp.o
[100%] Linking CXX executable buddhaOnCPU
/usr/bin/ld: CMakeFiles/buddhaOnCPU.dir/buddhaOnCPU.cpp.o: warning: relocation against `_ZN3tgx10Renderer3DINS_5RGB32ELNS_6ShaderE31167EfE20MAXVIEWPORTDIMENSIONE' in read-only section `.text._ZN3tgx10Renderer3DINS_5RGB32ELNS_6ShaderE31167EfE9setOffsetEii[_ZN3tgx10Renderer3DINS_5RGB32ELNS_6ShaderE31167EfE9setOffsetEii]'
/usr/bin/ld: CMakeFiles/buddhaOnCPU.dir/buddhaOnCPU.cpp.o: in function `tgx::Renderer3D<tgx::RGB32, (tgx::Shader)31167, float>::setViewportSize(int, int)':
/root/tgx/examples/CPU/buddhaOnCPU/../../../src/Renderer3D.inl:119: undefined reference to `tgx::Renderer3D<tgx::RGB32, (tgx::Shader)31167, float>::MAXVIEWPORTDIMENSION'
/usr/bin/ld: /root/tgx/examples/CPU/buddhaOnCPU/../../../src/Renderer3D.inl:120: undefined reference to `tgx::Renderer3D<tgx::RGB32, (tgx::Shader)31167, float>::MAXVIEWPORTDIMENSION'
/usr/bin/ld: CMakeFiles/buddhaOnCPU.dir/buddhaOnCPU.cpp.o: in function `tgx::Renderer3D<tgx::RGB32, (tgx::Shader)31167, float>::setOffset(int, int)':
/root/tgx/examples/CPU/buddhaOnCPU/../../../src/Renderer3D.inl:141: undefined reference to `tgx::Renderer3D<tgx::RGB32, (tgx::Shader)31167, float>::MAXVIEWPORTDIMENSION'
/usr/bin/ld: /root/tgx/examples/CPU/buddhaOnCPU/../../../src/Renderer3D.inl:142: undefined reference to `tgx::Renderer3D<tgx::RGB32, (tgx::Shader)31167, float>::MAXVIEWPORTDIMENSION'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/buddhaOnCPU.dir/build.make:227: buddhaOnCPU] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/buddhaOnCPU.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

liux-pro avatar Jun 16 '23 02:06 liux-pro

I found the linker error can be solved by removing static in this line. But I don't understand why this happened. https://github.com/vindar/tgx/blob/7263c7779c96ab7a325ce92a7ead418bfc08c68a/src/Renderer3D.h#L115

liux-pro avatar Jun 16 '23 02:06 liux-pro

Hi,

Yes, it is a strange bug. It compiles without trouble on Windows (with VS 2022) but fails with the error you mentioned on Ubuntu... Anyway, the correct way to code this is to use the constexpr qualifier instead of const. I just pulled the change and hopefully it now works ok. Thanks for reporting the bug.

vindar avatar Jun 16 '23 18:06 vindar