Skip to content

Commit

Permalink
Make this buildable on Ubuntu 20.04 with GCC 10
Browse files Browse the repository at this point in the history
...which has doctest 2.3.6, not 2.4.6 that we require.

Looks like the visibility rules are more complex (perhaps the operators
are auto-picked in GCC 11?), and indeed, GCC 10 requires that extra
attribute for visibility tweaking, otherwise we get this:

 /usr/bin/ld: CMakeFiles/test_schema_node.dir/tests/schema_node.cpp.o: in function `doctest::String doctest::detail::stringifyBinaryExpr<libyang::NodeType, libyang::NodeType>(libyang::NodeType const&, char const*, libyang::NodeType const&)':
 schema_node.cpp:(.text._ZN7doctest6detail19stringifyBinaryExprIN7libyang8NodeTypeES3_EENS_6StringERKT_PKcRKT0_[_ZN7doctest6detail19stringifyBinaryExprIN7libyang8NodeTypeES3_EENS_6StringERKT_PKcRKT0_]+0x43): undefined reference to `libyang::operator<<(std::ostream&, libyang::NodeType const&)'
 /usr/bin/ld: schema_node.cpp:(.text._ZN7doctest6detail19stringifyBinaryExprIN7libyang8NodeTypeES3_EENS_6StringERKT_PKcRKT0_[_ZN7doctest6detail19stringifyBinaryExprIN7libyang8NodeTypeES3_EENS_6StringERKT_PKcRKT0_]+0x66): undefined reference to `libyang::operator<<(std::ostream&, libyang::NodeType const&)'

This has an easy fix -- just add the LIBYANG_CPP_EXPORT after that
function, right (because if it's put before that function, it tries to
apply that attribute to the return type, std::string, and emits a
warning)? Not so fast, then we have MSVC which chokes on this:

 libyang-cpp\include\libyang-cpp/Enum.hpp(294,66): error C2144: syntax error: 'int' should be preceded by ';' [build-libyang-cpp\yang-cpp.vcxproj]
 libyang-cpp\include\libyang-cpp/Enum.hpp(294,84): warning C4091: '__declspec(dllexport)': ignored on left of 'int' when no variable is declared [build-libyang-cpp\yang-cpp.vcxproj]

Luckily, I'm not afraid to use these macros.

Change-Id: I370d85652542f4c731c6b01b6d7d484d2edbb987
  • Loading branch information
jktjkt committed Jun 29, 2022
1 parent 69f7ed2 commit 1d7c822
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ include(GenerateExportHeader)
generate_export_header(yang-cpp BASE_NAME libyang_cpp EXPORT_FILE_NAME libyang-cpp/export.h)

if(BUILD_TESTING)
find_package(doctest 2.4.6 REQUIRED)
find_package(doctest 2.3.6 REQUIRED)

add_library(DoctestIntegration STATIC
tests/doctest-integration.cpp
Expand Down
13 changes: 11 additions & 2 deletions include/libyang-cpp/Enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <cstdint>
#include <iosfwd>
#include <libyang-cpp/export.h>
#include <type_traits>
namespace libyang {
/**
Expand Down Expand Up @@ -290,6 +291,14 @@ constexpr ParseOptions operator|(const ParseOptions a, const ParseOptions b)
return implEnumBitOr(a, b);
}

std::ostream& operator<<(std::ostream& os, const NodeType& type);
std::ostream& operator<<(std::ostream& os, const ErrorCode& err);
std::ostream& operator<<(std::ostream& os, const NodeType& type)
#if defined(__GNUC__) && !defined(__llvm__) && __GNUC__ <= 10
LIBYANG_CPP_EXPORT
#endif
;
std::ostream& operator<<(std::ostream& os, const ErrorCode& err)
#if defined(__GNUC__) && !defined(__llvm__) && __GNUC__ <= 10
LIBYANG_CPP_EXPORT
#endif
;
}

0 comments on commit 1d7c822

Please sign in to comment.