1

context

OS: Ubuntu 18.04

Build: CMake 3.10.2

Compiler: gcc-9 (Ubuntu 9.2.1-17ubuntu1~18.04.1) 9.2.1 20191102

Configuration: x86_64, debug

action

I upgraded to the aforementioned gcc version and recompiled all third party libraries and my entire application code using this compiler. All libraries and applications were compiled with -m64 -std=c++17, the applications with -stdc++fs

With GCC-8, everything built fine, but running the whole thing caused a SEGFAULT at std::filesystem::current_path() after doing apt update, apt upgrade.

The whole application already ran successfully, before that.

error

I receive the subsequent multiple definition linker errors (+ one undefined reference error)

CMakeFiles/shirabe_resource_compiler.dir/code/source/extraction.cpp.o: In function `std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()':
/usr/include/c++/9/bits/shared_ptr_base.h:1118: multiple definition of `std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()'
CMakeFiles/shirabe_resource_compiler.dir/code/source/applicationmain.cpp.o:/usr/include/c++/9/bits/shared_ptr_base.h:1118: first defined here
CMakeFiles/shirabe_resource_compiler.dir/code/source/extraction.cpp.o: In function `std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()':
/usr/include/c++/9/bits/shared_ptr_base.h:1118: multiple definition of `std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()'
CMakeFiles/shirabe_resource_compiler.dir/code/source/applicationmain.cpp.o:/usr/include/c++/9/bits/shared_ptr_base.h:1118: first defined here
CMakeFiles/shirabe_resource_compiler.dir/code/source/extraction.cpp.o: In function `std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()':
/usr/include/c++/9/bits/shared_ptr_base.h:1118: multiple definition of `std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()'
CMakeFiles/shirabe_resource_compiler.dir/code/source/applicationmain.cpp.o:/usr/include/c++/9/bits/shared_ptr_base.h:1118: first defined here
CMakeFiles/shirabe_resource_compiler.dir/code/source/extraction.cpp.o: In function `std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()':
/usr/include/c++/9/bits/shared_ptr_base.h:1118: multiple definition of `std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()'
CMakeFiles/shirabe_resource_compiler.dir/code/source/applicationmain.cpp.o:/usr/include/c++/9/bits/shared_ptr_base.h:1118: first defined here
CMakeFiles/shirabe_resource_compiler.dir/code/source/shadercompilationunit.cpp.o: In function `std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()':
/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/nlohmann_json/linux64/debug/include/nlohmann/json.hpp:8916: multiple definition of `std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()'
CMakeFiles/shirabe_resource_compiler.dir/code/source/applicationmain.cpp.o:/usr/include/c++/9/bits/shared_ptr_base.h:1118: first defined here
CMakeFiles/shirabe_resource_compiler.dir/code/source/shadercompilationunit.cpp.o: In function `std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()':
/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/nlohmann_json/linux64/debug/include/nlohmann/json.hpp:8916: multiple definition of `std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()'
CMakeFiles/shirabe_resource_compiler.dir/code/source/applicationmain.cpp.o:/usr/include/c++/9/bits/shared_ptr_base.h:1118: first defined here
CMakeFiles/shirabe_resource_compiler.dir/code/source/shadercompilationunit.cpp.o: In function `std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()':
/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/nlohmann_json/linux64/debug/include/nlohmann/json.hpp:8916: multiple definition of `std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()'
CMakeFiles/shirabe_resource_compiler.dir/code/source/applicationmain.cpp.o:/usr/include/c++/9/bits/shared_ptr_base.h:1118: first defined here
CMakeFiles/shirabe_resource_compiler.dir/code/source/shadercompilationunit.cpp.o: In function `std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()':
/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/nlohmann_json/linux64/debug/include/nlohmann/json.hpp:8916: multiple definition of `std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()'
CMakeFiles/shirabe_resource_compiler.dir/code/source/applicationmain.cpp.o:/usr/include/c++/9/bits/shared_ptr_base.h:1118: first defined here
CMakeFiles/shirabe_resource_compiler.dir/code/source/applicationmain.cpp.o: In function `std::filesystem::__cxx11::path::path(std::basic_string_view<char, std::char_traits<char> >, std::filesystem::__cxx11::path::_Type)':
/usr/include/c++/9/bits/fs_path.h:477: undefined reference to `std::filesystem::__cxx11::path::_List::type(std::filesystem::__cxx11::path::_Type)'
collect2: error: ld returned 1 exit status

more context

The COLLECT_GCC_OPTIONS output is:

COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/9/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-std=c++17' '-fexceptions' '-pthread' '-fPIE' '-m64' '-ggdb3' '-Wextra' '-Wno-extra-semi' '-Wno-reserved-id-macro' '-Wno-ignored-qualifiers' '-fkeep-inline-functions' '-fkeep-static-functions' '-g' '-o' '../../_deploy/linux64/debug/bin/shirabe_resource_compiler_x64d' '-L/home/dotti/workspaces/shirabeengine/shirabeengine/_deploy/linux64/debug/lib' '-L/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/spirv_cross/linux64/debug/lib' '-L/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/spirv_tools/linux64/debug/lib' '-L/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/cryptopp/linux64/debug/lib' '-L/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/glslang/linux64/debug/lib' '-L/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/fmt/linux64/debug/lib' '-L/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/libxml2/linux64/debug/lib' '-L/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/zlib/linux64/debug/lib' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/9/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/9/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper -plugin-opt=-fresolution=/tmp/cc12pvJX.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o ../../_deploy/linux64/debug/bin/shirabe_resource_compiler_x64d /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o -L/home/dotti/workspaces/shirabeengine/shirabeengine/_deploy/linux64/debug/lib -L/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/spirv_cross/linux64/debug/lib -L/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/spirv_tools/linux64/debug/lib -L/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/cryptopp/linux64/debug/lib -L/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/glslang/linux64/debug/lib -L/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/fmt/linux64/debug/lib -L/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/libxml2/linux64/debug/lib -L/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/zlib/linux64/debug/lib -L/usr/lib/gcc/x86_64-linux-gnu/9 -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/9/../../.. CMakeFiles/shirabe_resource_compiler.dir/code/source/applicationmain.cpp.o CMakeFiles/shirabe_resource_compiler.dir/code/source/extraction.cpp.o CMakeFiles/shirabe_resource_compiler.dir/code/source/shadercompilationunit.cpp.o -rpath /home/dotti/workspaces/shirabeengine/shirabeengine/_deploy/linux64/debug/lib:/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/spirv_cross/linux64/debug/lib:/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/spirv_tools/linux64/debug/lib:/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/cryptopp/linux64/debug/lib:/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/glslang/linux64/debug/lib:/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/fmt/linux64/debug/lib:/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/libxml2/linux64/debug/lib:/home/dotti/workspaces/shirabeengine/shirabeengine/../thirdparty/_deploy/zlib/linux64/debug/lib --whole-archive ../../_deploy/linux64/debug/lib/libmaterial_x64d_a.a --no-whole-archive --whole-archive ../../_deploy/linux64/debug/lib/libasset_x64d_a.a --no-whole-archive --whole-archive ../../_deploy/linux64/debug/lib/libgraphicsapi_x64d_a.a --no-whole-archive --whole-archive ../../_deploy/linux64/debug/lib/libresources_x64d_a.a --no-whole-archive --whole-archive ../../_deploy/linux64/debug/lib/libmath_x64d_a.a --no-whole-archive --whole-archive ../../_deploy/linux64/debug/lib/libutility_x64d_a.a --no-whole-archive --whole-archive ../../_deploy/linux64/debug/lib/libcore_x64d_a.a --no-whole-archive --whole-archive ../../_deploy/linux64/debug/lib/libbase_x64d_a.a --no-whole-archive -lspirv-cross-core -lspirv-cross-cpp -lspirv-cross-glsl -lspirv-cross-msl -lspirv-cross-reflect -lspirv-cross-util -lcryptopp -lglslang -lOGLCompiler -lHLSL -lSPIRV -lSPVRemapper -lOSDependent -lfmtd -lxml2 -lz -ldl -lstdc++ -lm -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o

Remarks: I have a larger list of static-libraries, which are linked into a common shared-object. Any -l option after -dl is appended by CMake, I don't set them.

what I have done already

  • As I upgraded from GCC-8, I removed -lstdc++fs and replaced all occurrences of #include <experimental/filesystem> with #include <filesystem> and updated all references and namespace usages
  • I deleted all thirdparty sources, build files and deployment output and fetched the sources freshly and did a full rebuild from scratch
  • I cleaned up header includes and sources, removed unused includes, definitions and functions, and so on --> no effect
  • I analyzed the linker errors and went into the nlohmann::json library and searched for occurrences of std::shared_ptr<std::filesystem ... --> No occurrence found
  • I analyzed the source code and code included by it affected by the three .o-files listed. --> no occurrences of std::shared_ptr<std::filesystem ... found
  • I checked though all implicit conversions to and from std::filesystem::... and std::shared_ptr<... --> nothing found
  • I went through all files that I changed recently to find errors with <> and whatever syntactic keywords --> nothing found
  • I crawled through many many posts at SO regarding multiple definition errors and subsequently made sure that everything is built with the same compiler and options. --> Unsolved

short

I can't explain why the code fails.

HALP!

I am stuck at this point. Did anyone encounter such issues beforehand?

I am grateful for any clue on how to track this down.

UPDATE

Following nm's advice, I performed nm -C extraction.cpp.o | grep _Dir:

0000000000000000 W bool std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>::owner_before<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack>(std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2> const&) const
0000000000000000 W bool std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>::owner_before<std::filesystem::__cxx11::_Dir>(std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2> const&) const
                 U std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>::__shared_ptr(std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>&&)
00000000000005c4 T std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()
000000000000059a T std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()
0000000000000000 W std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr()
0000000000000000 W std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr()
0000000000000000 n std::__shared_ptr<std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr()
                 U std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>::__shared_ptr(std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>&&)
0000000000000570 T std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()
0000000000000546 T std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()
0000000000000000 W std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr()
0000000000000000 W std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr()
0000000000000000 n std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr()

Yep, weak symbols...

UPDATE 2

Appears to be a compiler bug in the inofficial distribution of GCC-9 I use. Went back to GCC-8 with a few fixes and the issues are resolved.

MABVT
  • 1,350
  • 10
  • 17
  • 3
    The shared_ptr to _Dir is internal to fs implementation. The multiply defined symbols should be weak. Do `nm -C extraction.cpp.o | grep _Dir` and see of these symbols are indeed weak. – n. m. could be an AI Nov 15 '19 at 08:56
  • @n.'pronouns'm. Yep, weak symbols, but partially undefined. See update to the post. – MABVT Nov 15 '19 at 09:40
  • (W)eak, (U)ndefined and (n)on-writable are OK. (T)ext is not. The symbol is a template instantiation, and can be only emitted as (T)ext if it is explicitly instantiated. This could be a gcc bug, or an artifact of incomplete rebuild. – n. m. could be an AI Nov 15 '19 at 10:14
  • Is the incomplete rebuild on my side? – MABVT Nov 15 '19 at 10:15
  • 1
    Perhaps, it's hard to tell. I don't get these symbols at all. Try rebuilding objects in question. – n. m. could be an AI Nov 15 '19 at 10:31
  • So I checked the whole thing a little and conclude (for now), that it is a compiler bug, since the gcc9 I use is no official distro build (kubuntu 18.04 has gcc-8 officially). I changed everything back to gcc-8 and fixed one error in my code and got the stuff running now. I will try again, once there's an official distribution. – MABVT Nov 15 '19 at 14:24

0 Answers0