thezbyg / gpick

Advanced color picker written in C++ using GTK+ toolkit
BSD 3-Clause "New" or "Revised" License
376 stars 33 forks source link

[FTBS] opensuse 15.4 linking of tests ok in v0.2.6 but fails both in v0.3 and latest r.46f826c #208

Open Corin-EU opened 2 years ago

Corin-EU commented 2 years ago

On openSUSE 15.4, I can successfully build v0.2.6, and there are no errors.

If I try the same procedure with v0.3, cmake makes no complaints about lua depenencies

      -- The CXX compiler identification is GNU 8.2.1
      -- Checking for module 'gtk+-3.0>=3.0'
      --   Found gtk+-3.0, version 3.24.31
      -- Checking for one of the modules 'lua5.4-c++>=5.4;lua5-c++>=5.4;lua5.3-c++>=5.3;lua5-c++>=5.3;lua-c++>=5.3;lua5.2-c++>=5.2;lua-c++>=5.2'
      -- Checking for module 'expat>=1.0'
      --   Found expat, version 2.4.4

but linking of the tests fails with lots of error message about undefined references to lua functions

     [ 19%] Linking CXX executable tests
     Script.cpp:(.text+0x19): undefined reference to `lua_pushstring(lua_State*, char const*)'
     /usr/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/bin/ld: CMakeFiles/tests.dir/source/test/Script.cpp.o: in function `error(lua_State*)':
     Script.cpp:(.text+0x53): undefined reference to `lua_getglobal(lua_State*, char const*)'
     /usr/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/bin/ld: Script.cpp:(.text+0x64): undefined reference to `lua_touserdata(lua_State*, int)'
     /usr/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/bin/ld: Script.cpp:(.text+0x79): undefined reference to `lua_settop(lua_State*, int)'
     /usr/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/bin/ld: Script.cpp:(.text+0xc1): undefined reference to `luaL_error(lua_State*, char const*, ...)'
     /usr/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/bin/ld: CMakeFiles/tests.dir/source/test/Script.cpp.o: in function `script::register_extension::test_method()::{lambda(lua::Script&)#1}::operator()(lua::Script&) const':
     Script.cpp:(.text+0x647): undefined reference to `luaL_checkversion_(lua_State*, double, unsigned long)'
     ....  etc etc

What has changed with version 0.3 to cause this problem and why did cmake not complain?

If I try to build the very latest revision r.46f826c, then cmake again makes no complaints, but building fails even sooner with

  -- The CXX compiler identification is GNU 8.2.1

 Scanning dependencies of target gpick-math
 [  1%] Building CXX object CMakeFiles/gpick-math.dir/source/math/BinaryTreeQuantization.cpp.o
 In file included from /srv/repository/git/gpick/source/math/BinaryTreeQuantization.cpp:19:
 /srv/repository/git/gpick/source/math/BinaryTreeQuantization.h:23:10: fatal error: memory_resource: No such file or directory
 #include <memory_resource>
                  ^~~~~~~~~~~~~~~~~
 compilation terminated.
 make[2]: *** [CMakeFiles/gpick-math.dir/build.make:82: CMakeFiles/gpick-math.dir/source/math/BinaryTreeQuantization.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:115: CMakeFiles/gpick-math.dir/all] Error 2
make: *** [Makefile:149: all] Error 2

Since cmake checks the version of the C++ compiler should it not be spitting out an error if the wrong version is being used?

Setting the environmental variable CXX="g++-10" is of course the solution to this, and then compilation continues but the same linking problem of the tests and the build fails.

-- The CXX compiler identification is GNU 10.3.0

 [ 31%] Linking CXX executable tests
 /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: CMakeFiles/tests.dir/source/Converter.cpp.o: in function  `Converter::serialize[abi:cxx11](ColorObject const&, ConverterSerializePosition const&)':
 Converter.cpp:(.text+0x398): undefined reference to `lua_gettop(lua_State*)'
 /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x3ed): undefined reference to   `lua_createtable(lua_State*, int, int)'
 /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x40d): undefined reference to `lua_pushboolean(lua_State*, int)'
 /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x423): undefined reference to `lua_setfield(lua_State*, int, char const*)'
 /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x443): undefined reference to `lua_pushboolean(lua_State*, int)'
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x459): undefined reference to `lua_setfield(lua_State*, int, char const*)'
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x47a): undefined reference to `lua_pushinteger(lua_State*, long long)'
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x490): undefined reference to `lua_setfield(lua_State*, int, char const*)'
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x4b1): undefined reference to `lua_pushinteger(lua_State*, long long)'
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x4c7): undefined reference to `lua_setfield(lua_State*, int, char const*)'
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x4ee): undefined reference to `lua_pcallk(lua_State*, int, int, int, long, int (*)(lua_State*, int, long))'
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x50c): undefined reference to `lua_type(lua_State*, int)'
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x53c): undefined reference to `luaL_checklstring(lua_State*, int, unsigned long*)'
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x572): undefined reference to `lua_settop(lua_State*, int)'
 /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x5fa): undefined reference to `lua_tolstring(lua_State*, int, unsigned long*)'
 /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x623): undefined reference to `lua_settop(lua_State*, int)'
 /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: CMakeFiles/tests.dir/source/Converter.cpp.o: in function `Converter::deserialize(char const*, ColorObject&, float&)':
 Converter.cpp:(.text+0x767): undefined reference to `lua_gettop(lua_State*)'
 /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x78d): undefined reference to `lua_pushstring(lua_State*, char const*)'
 /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x7c7): undefined reference to `lua_pcallk(lua_State*, int, int, int, long, int (*)(lua_State*, int, long))'
  .... etc etc

The version of lua on the system is 5.4.3 and as I stated at the top, v0.2.6 had no problem finding it and linking the tests with the lua library.

thezbyg commented 2 years ago

Hi, most likely this is due to switch to C++ Lua library variant in 892a81ed369b0ae5d87a438ff77236e9c7f27949. Linker errors are caused by Lua function declarations using C++ linkage when Lua library exports C style functions. Debian based distributions have this patch: https://sources.debian.org/patches/lua5.4/5.4.2-2/0003-extern_C.patch/ Without this patch, all Lua header inclusions must be wrapped in extern "C" { } block when used from C++ code. I will restore these blocks.

GCC 8.2 is too old and is missing some C++17 features. GCC 10 should work once Lua includes are fixed.

thezbyg commented 2 years ago

Should be fixed in a8bc29c60d57933d9e8e8cb930d8e06586e0d315

Corin-EU commented 2 years ago

Thank you for looking at this problem.

opensuse 15.4 g++-10 (SUSE Linux) 10.4.0

latest gpick r.a8bc29c

I anticipated reporting back that all was now working, but I am still getting the same errors

              [ 31%] Linking CXX executable tests
              /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: CMakeFiles/tests.dir/source/Converter.cpp.o: in function `Converter::serialize[abi:cxx11](ColorObject const&, ConverterSerializePosition const&)':
               Converter.cpp:(.text+0x398): undefined reference to `lua_gettop'
              /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: Converter.cpp:(.text+0x3ed): undefined reference to `lua_createtable'

etc

So in the "build" sub-directory, I did a make VERBOSE=1

          /usr/local/stow/Development/cmake-3.19.6/bin/cmake -E cmake_link_script CMakeFiles/tests.dir/link.txt --verbose=1
          /usr/bin/g++-10 CMakeFiles/tests.dir/CMakeFiles/Version.cpp.o CMakeFiles/tests.dir/source/ColorList.cpp.o CMakeFiles/tests.dir/source/ColorObject.cpp.o CMakeFiles/tests.dir/source/Converter.cpp.o CMakeFiles/tests.dir/source/Converters.cpp.o CMakeFiles/tests.dir/source/ErrorCode.cpp.o CMakeFiles/tests.dir/source/EventBus.cpp.o CMakeFiles/tests.dir/source/FileFormat.cpp.o CMakeFiles/tests.dir/source/InternalConverters.cpp.o CMakeFiles/tests.dir/source/test/BinaryTreeQuantization.cpp.o CMakeFiles/tests.dir/source/test/Color.cpp.o CMakeFiles/tests.dir/source/test/Common.cpp.o CMakeFiles/tests.dir/source/test/Dynv.cpp.o CMakeFiles/tests.dir/source/test/DynvBinary.cpp.o CMakeFiles/tests.dir/source/test/EventBus.cpp.o CMakeFiles/tests.dir/source/test/FileFormat.cpp.o CMakeFiles/tests.dir/source/test/First.cpp.o CMakeFiles/tests.dir/source/test/Format.cpp.o CMakeFiles/tests.dir/source/test/InternalConverters.cpp.o CMakeFiles/tests.dir/source/test/Main.cpp.o CMakeFiles/tests.dir/source/test/Matrix.cpp.o CMakeFiles/tests.dir/source/test/OctreeColorQuantization.cpp.o CMakeFiles/tests.dir/source/test/Ref.cpp.o CMakeFiles/tests.dir/source/test/Result.cpp.o CMakeFiles/tests.dir/source/test/Scoped.cpp.o CMakeFiles/tests.dir/source/test/Script.cpp.o CMakeFiles/tests.dir/source/test/Span.cpp.o CMakeFiles/tests.dir/source/test/TextFileParser.cpp.o CMakeFiles/tests.dir/source/test/Vector.cpp.o CMakeFiles/gpick-color.dir/source/Color.cpp.o CMakeFiles/gpick-math.dir/source/math/BinaryTreeQuantization.cpp.o CMakeFiles/gpick-math.dir/source/math/Empty.cpp.o CMakeFiles/gpick-math.dir/source/math/OctreeColorQuantization.cpp.o CMakeFiles/gpick-dynv.dir/source/dynv/Binary.cpp.o CMakeFiles/gpick-dynv.dir/source/dynv/Map.cpp.o CMakeFiles/gpick-dynv.dir/source/dynv/Types.cpp.o CMakeFiles/gpick-dynv.dir/source/dynv/Variable.cpp.o CMakeFiles/gpick-dynv.dir/source/dynv/Xml.cpp.o CMakeFiles/gpick-lua.dir/source/lua/Color.cpp.o CMakeFiles/gpick-lua.dir/source/lua/ColorObject.cpp.o CMakeFiles/gpick-lua.dir/source/lua/Ref.cpp.o CMakeFiles/gpick-lua.dir/source/lua/Script.cpp.o CMakeFiles/gpick-parser.dir/source/parser/TextFile.cpp.o CMakeFiles/gpick-parser.dir/CMakeFiles/TextFileParser.cpp.o CMakeFiles/gpick-common.dir/source/common/Convert.cpp.o CMakeFiles/gpick-common.dir/source/common/Format.cpp.o CMakeFiles/gpick-common.dir/source/common/Ref.cpp.o CMakeFiles/gpick-common.dir/source/common/StringOrView.cpp.o -o tests  /usr/lib64/libboost_unit_test_framework.so -lexpat -lm -pthread

which obviously gave the same error.

I then repeated the command and put a "-llua" at the very end, ie just after "-lm -pthread" and then there was no error and linking was successful.

So it would appear the error is somewhere in the CMakefile process and that the "lua" library dependency is not being added to the needed shared library link list for some reason (unlike back in v0.2.6).