Trying Link a Library, Compiler Can Not Find The Size of Type’s or Program Crashes on First Refrence To Them

  c++, conan, dependencies, linker, sizeof

I have been trying to use OpenXLSX in my project for school, to do this I am creating a conan package for it (to be uniform with the rest of the project and to ensure it works on my professor’s machine). Everything builds just fine, including the demos and I have run the unit tests with no problem (except for a few it seems, I think when it is testing the WinZip functionality, which makes sense because I am building this in an ubuntu:latest container [20.04 I think]). However when I go to try to use the library, I include the OpenXLSX header and get this error

In file included from /usr/include/c++/9/memory:80,
                 from /root/.conan/data/openxlsx/0.2.0/build/openxlsx/package/b911f48570f9bb2902d9e83b2b9ebf9d376c8c56/include/headers/XLCellValue.hpp:54,
                 from /root/.conan/data/openxlsx/0.2.0/build/openxlsx/package/b911f48570f9bb2902d9e83b2b9ebf9d376c8c56/include/headers/XLCell.hpp:56,
                 from /root/.conan/data/openxlsx/0.2.0/build/openxlsx/package/b911f48570f9bb2902d9e83b2b9ebf9d376c8c56/include/OpenXLSX.hpp:49,
                 from /project/Source/ExcelData.hpp:4,
                 from /project/Source/ExcelData.cpp:1:
/usr/include/c++/9/bits/unique_ptr.h: In instantiation of 'void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = pugi::xml_node]':
/usr/include/c++/9/bits/unique_ptr.h:292:17:   required from 'std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = pugi::xml_node; _Dp = std::default_delete<pugi::xml_node>]'
/root/.conan/data/openxlsx/0.2.0/build/openxlsx/package/b911f48570f9bb2902d9e83b2b9ebf9d376c8c56/include/headers/XLCellRange.hpp:102:9:   required from here
/usr/include/c++/9/bits/unique_ptr.h:79:16: error: invalid application of 'sizeof' to incomplete type 'pugi::xml_node'
   79 |  static_assert(sizeof(_Tp)>0,
      |                ^~~~~~~~~~~
In file included from /usr/include/c++/9/memory:80,
                 from /root/.conan/data/openxlsx/0.2.0/build/openxlsx/package/b911f48570f9bb2902d9e83b2b9ebf9d376c8c56/include/headers/XLCellValue.hpp:54,
                 from /root/.conan/data/openxlsx/0.2.0/build/openxlsx/package/b911f48570f9bb2902d9e83b2b9ebf9d376c8c56/include/headers/XLCell.hpp:56,
                 from /root/.conan/data/openxlsx/0.2.0/build/openxlsx/package/b911f48570f9bb2902d9e83b2b9ebf9d376c8c56/include/OpenXLSX.hpp:49,
                 from /project/Source/ExcelData.hpp:4,
                 from /project/Source/ExcelData.cpp:1:
/usr/include/c++/9/bits/unique_ptr.h: In instantiation of 'void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = pugi::xml_node]':
/usr/include/c++/9/bits/unique_ptr.h:292:17:   required from 'std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = pugi::xml_node; _Dp = std::default_delete<pugi::xml_node>]'
/root/.conan/data/openxlsx/0.2.0/build/openxlsx/package/b911f48570f9bb2902d9e83b2b9ebf9d376c8c56/include/headers/XLCellRange.hpp:102:9:   required from here
/usr/include/c++/9/bits/unique_ptr.h:79:16: error: invalid application of 'sizeof' to incomplete type 'pugi::xml_node'
   79 |  static_assert(sizeof(_Tp)>0,
      |                ^~~~~~~~~~~
make[2]: *** [CMakeFiles/server.dir/build.make:115: CMakeFiles/server.dir/Source/ExcelData.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [CMakeFiles/tests.dir/build.make:115: CMakeFiles/tests.dir/Source/ExcelData.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:105: CMakeFiles/server.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/tests.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

It seems it cant find the compiler can not find the size of the pugi types. I looked into XLXmlParser.hpp and it seems to take advantage of SFINAE and doesent include the PUGI header.

I tried manually inserting it (via conan script) but it did not work.

Then I tried including the PUGI header in my program, I got the same error until I put the header AFTER the OpenXLSX.hpp header. It compiled but segfaulted on the first reference to anything PUGI (in this case inside isOpen … I forget where). I looked at the example’s CMakeLists.txt files I found that a compile time definition was made so I tried to target_compile_definitions(Demo1 PRIVATE OPENXLSX_STATIC_DEFINE) I tried adding that but it seems to have no effect. I am at a bit of a loss.

Thank you for reading!

Source: Windows Questions C++

LEAVE A COMMENT