Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

how to compile with clang ? #324

Closed
freboat opened this issue Jun 11, 2019 · 5 comments
Closed

how to compile with clang ? #324

freboat opened this issue Jun 11, 2019 · 5 comments

Comments

@freboat
Copy link
Contributor

freboat commented Jun 11, 2019

i try it like that:
$export CC=/usr/bin/clang-3.6
$export CXX=/usr/bin/clang++-3.6
$cmake ..
$make

but i got a error like below:
In file included from /home/brook/pmem/libpmemobj-cpp/tests/allocator/allocator.cpp:43:
/home/brook/pmem/libpmemobj-cpp/include/libpmemobj++/transaction.hpp:470:29: error: no member named 'is_trivially_copyable' in
namespace 'std'
typename std::enable_if<IS_TRIVIALLY_COPYABLE(T), T>::type * =
^~~~~~~~~~~~~~~~~~~~~~~~
/home/brook/pmem/libpmemobj-cpp/include/libpmemobj++/detail/common.hpp:101:39: note: expanded from macro 'IS_TRIVIALLY_COPYABLE'
#define IS_TRIVIALLY_COPYABLE(T) std::is_trivially_copyable::value
~~~~~^
In file included from /home/brook/pmem/libpmemobj-cpp/tests/allocator/allocator.cpp:43:
/home/brook/pmem/libpmemobj-cpp/include/libpmemobj++/transaction.hpp:470:51: error: 'T' does not refer to a value
typename std::enable_if<IS_TRIVIALLY_COPYABLE(T), T>::type * =
^
/home/brook/pmem/libpmemobj-cpp/include/libpmemobj++/detail/common.hpp:101:61: note: expanded from macro 'IS_TRIVIALLY_COPYABLE'
#define IS_TRIVIALLY_COPYABLE(T) std::is_trivially_copyable::value
^
/home/brook/pmem/libpmemobj-cpp/include/libpmemobj++/transaction.hpp:469:21: note: declared here
template <typename T,
^
/home/brook/pmem/libpmemobj-cpp/include/libpmemobj++/transaction.hpp:470:59: error: no type named 'type' in the global namespace
typename std::enable_if<IS_TRIVIALLY_COPYABLE(T), T>::type * =
~~^
/home/brook/pmem/libpmemobj-cpp/include/libpmemobj++/transaction.hpp:470:66: error: expected member name or ';' after declaration
specifiers
typename std::enable_if<IS_TRIVIALLY_COPYABLE(T), T>::type * =
~~~~~~ ^
/home/brook/pmem/libpmemobj-cpp/include/libpmemobj++/transaction.hpp:404:14: error: use of undeclared identifier 'add_lock'
auto err = add_lock(locks...);
^
/home/brook/pmem/libpmemobj-cpp/tests/allocator/allocator.cpp:95:23: note: in instantiation of function template specialization
'pmem::obj::transaction::run<>' requested here
nvobj::transaction::run(pop, [&] {
^
5 errors generated.

@szyrom
Copy link

szyrom commented Jun 11, 2019

Hi,
thanks for this catch. clang 3.6 does not fully support all C++11 features (traits in this case).
It should work with this PR #325 (will be merged after code review).

@igchor
Copy link
Contributor

igchor commented Jun 11, 2019

@freboat I strongly recommend to upgrade your compiler, this should fix the issue. However, if you want to use clang 3.6 you can wait until #325 is merged or apply the following patch :

---
 include/libpmemobj++/detail/common.hpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/libpmemobj++/detail/common.hpp b/include/libpmemobj++/detail/common.hpp
index d570464..aba2063 100644
--- a/include/libpmemobj++/detail/common.hpp
+++ b/include/libpmemobj++/detail/common.hpp
@@ -95,7 +95,15 @@
  * and 0 in gcc. It means that for gcc < 5 IS_TRIVIALLY_COPYABLE is more
  * restrictive than is_trivially_copyable.
  */
+#if !defined(LIBPMEMOBJ_CPP_USE_HAS_TRIVIAL_COPY)
 #if !defined(__clang__) && defined(__GNUG__) && __GNUC__ < 5
+#define LIBPMEMOBJ_CPP_USE_HAS_TRIVIAL_COPY 1
+#else
+#define LIBPMEMOBJ_CPP_USE_HAS_TRIVIAL_COPY 0
+#endif
+#endif
+
+#if LIBPMEMOBJ_CPP_USE_HAS_TRIVIAL_COPY
 #define IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T)
 #else
 #define IS_TRIVIALLY_COPYABLE(T) std::is_trivially_copyable<T>::value
-- 

After that, to compile libpmemobj-cpp tests and examples with your clang version please run cmake with: -DCMAKE_CXX_FLAGS=-DLIBPMEMOBJ_CPP_USE_HAS_TRIVIAL_COPY=1. If you want to compile your application with libmemobj-cpp using clang 3.6 you must set LIBPMEMOBJ_CPP_USE_HAS_TRIVIAL_COPY=1 in your code or during compilation.

@freboat
Copy link
Contributor Author

freboat commented Jun 12, 2019

@szyrom & @igchor thanks for your kind reply,
i updated clang to 3.9 run cmake with -DCMAKE_CXX_FLAGS=-DLIBPMEMOBJ_CPP_USE_HAS_TRIVIAL_COPY=1
but got another error:

In file included from /home/brook/pmem/libpmemobj-cpp/tests/string_exceptions/string_exceptions.cpp:35:
/home/brook/pmem/libpmemobj-cpp/include/libpmemobj++/experimental/slice.hpp:79:15: error: no member named 'out_of_range' in namespace
'std'
throw std::out_of_range("pmem::obj::slice");
~~~~~^
/home/brook/pmem/libpmemobj-cpp/include/libpmemobj++/experimental/slice.hpp:137:15: error: no member named 'out_of_range' in namespace
'std'
throw std::out_of_range("pmem::obj::slice");
~~~~~^

@freboat
Copy link
Contributor Author

freboat commented Jun 12, 2019

@ALL, i have fixed the error,
include/libpmemobj++/experimental/slice.hpp lost the stdexcept headfile, just add and it works:

#include <stdexcept>

@freboat freboat closed this as completed Jun 12, 2019
@szyrom
Copy link

szyrom commented Jun 12, 2019

@freboat Will you submit pull request? Your contribution is more than welcome :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants