Cassandra cpp-driver compile error - c++

I'm trying to install Cassandra cpp-driver in Ubuntu.
I've done the steps specified in DataStax C/C++ Driver for Apache Cassandra (Beta), but i keep getting the following compile error.
[ 1%] Building CXX object CMakeFiles/cassandra.dir/src/buffer_collection.cpp.o
In file included from /root/libraries/cass_cpp-driver/git2/cpp-driver/src/session.hpp:29:0, from /root/libraries/cass_cpp-driver/git2/cpp-driver/src/types.hpp:22, from /root/libraries/cass_cpp-driver/git2/cpp-driver/src/buffer_collection.cpp:19:
/root/libraries/cass_cpp-driver/git2/cpp-driver/src/logger.hpp: In member function 'int cass::Logger::init()':
/root/libraries/cass_cpp-driver/git2/cpp-driver/src/logger.hpp:40:59: error: no matching function for call to 'cass::AsyncQueue<cass::MPMCQueue<cass::Logger::LogMessage*> >::init(uv_loop_t*, cass::Logger* const, void (&)(uv_async_t*, int))'
int init() { return log_queue_.init(loop(), this, on_log); }
^
/root/libraries/cass_cpp-driver/git2/cpp-driver/src/logger.hpp:40:59: note: candidate is:
In file included from /root/libraries/cass_cpp-driver/git2/cpp-driver/src/event_thread.hpp:21:0,
from /root/libraries/cass_cpp-driver/git2/cpp-driver/src/session.hpp:20,
from /root/libraries/cass_cpp-driver/git2/cpp-driver/src/types.hpp:22,
from /root/libraries/cass_cpp-driver/git2/cpp-driver/src/buffer_collection.cpp:19:
/root/libraries/cass_cpp-driver/git2/cpp-driver/src/async_queue.hpp:34:7: note: int cass::AsyncQueue<Q>::init(uv_loop_t*, void*, uv_async_cb) [with Q = cass::MPMCQueue<cass::Logger::LogMessage*>; uv_loop_t = uv_loop_s; uv_async_cb = void (*)(uv_async_s*); uv_async_t = uv_async_s] <near match>
int init(uv_loop_t* loop, void* data, uv_async_cb async_cb) {
^
/root/libraries/cass_cpp-driver/git2/cpp-driver/src/async_queue.hpp:34:7: note: no known conversion for argument 3 from 'void(uv_async_t*, int) {aka void(uv_async_s*, int)}' to 'uv_async_cb {aka void (*)(uv_async_s*)}'
make[2]: *** [CMakeFiles/cassandra.dir/src/buffer_collection.cpp.o] Error 1
make[1]: *** [CMakeFiles/cassandra.dir/all] Error 2
make: *** [all] Error 2

I've already fixed this compile errors in Cassandra cpp-driver, by down-versioning libuv to version libuv-0.10, the compile errors will be gone.
It seems that the latest updates for libuv is not yet supported by Cassandra cpp-driver.

Related

error: could not convert ‘print’ from ‘void (*)(int)’ to ‘std::function<void()>’

Following on from a previous question, I was pointed to an answer. The answer however involved a lambda function and I am trying to pass a normal function through.
Using the below code as an example:
#include <iostream>
#include <functional>
void forloop(std::function<void()> func, int arg) {
func(arg);
}
void print(int number) {
std::cout << number << std::endl;
}
int main() {
int n = 5;
forloop(print, n);
}
The following error is returned in CLion.
/home/dave/JetBrains/CLion/bin/cmake/bin/cmake --build /home/dave/CLionProjects/csv/cmake-build-debug --target csv -- -j 2
Scanning dependencies of target csv
[ 50%] Building CXX object CMakeFiles/csv.dir/main.cpp.o
/home/dave/CLionProjects/csv/main.cpp: In function ‘void forloop(std::function<void()>, int)’:
/home/dave/CLionProjects/csv/main.cpp:5:13: error: no match for call to ‘(std::function<void()>) (int&)’
func(arg);
^
In file included from /home/dave/CLionProjects/csv/main.cpp:2:0:
/usr/include/c++/6/functional:2122:5: note: candidate: _Res std::function<_Res(_ArgTypes ...)>::operator()(_ArgTypes ...) const [with _Res = void; _ArgTypes = {}]
function<_Res(_ArgTypes...)>::
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/6/functional:2122:5: note: candidate expects 0 arguments, 1 provided
/home/dave/CLionProjects/csv/main.cpp: In function ‘int main()’:
/home/dave/CLionProjects/csv/main.cpp:16:21: error: could not convert ‘print’ from ‘void (*)(int)’ to ‘std::function<void()>’
forloop(print, n);
^
CMakeFiles/csv.dir/build.make:62: recipe for target 'CMakeFiles/csv.dir/main.cpp.o' failed
make[3]: *** [CMakeFiles/csv.dir/main.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/csv.dir/all' failed
make[2]: *** [CMakeFiles/csv.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/csv.dir/rule' failed
make[1]: *** [CMakeFiles/csv.dir/rule] Error 2
Makefile:118: recipe for target 'csv' failed
make: *** [csv] Error 2
Apologies if this questions seems silly - I am a C++ noob.
std::function<void()> means "function that returns void and takes no arguments". You're trying to pass print instead, which is a "function that returns void and takes an int". The types are mismatched.
Change forloop to:
void forloop(std::function<void(int)> func, int arg) { /* ... */ }
Also, don't use std::function to pass lambdas unless you have a good reason to do so. I suggest reading my article on the subject: "passing functions to functions".

opencv - cmake mingw32-make error [duplicate]

opencv installation using mingw32-make command in windows 10 platform, then likely end up in getting the below error.
Windows version : 10
OpenCv:3.2.0
Please suggest me in installing.
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In constructor 'testing::internal::Mutex::Mutex()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8829:45: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in initialization
critical_section_(new CRITICAL_SECTION) {
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8830:48: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
::InitializeCriticalSection(critical_section_);
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In destructor 'testing::internal::Mutex::~Mutex()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8840:46: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'PCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void DeleteCriticalSection(PCRITICAL_SECTION)'
::DeleteCriticalSection(critical_section_);
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::Lock()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8848:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void EnterCriticalSection(LPCRITICAL_SECTION)'
::EnterCriticalSection(critical_section_);
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::Unlock()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8858:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void LeaveCriticalSection(LPCRITICAL_SECTION)'
::LeaveCriticalSection(critical_section_);
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::ThreadSafeLazyInit()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8879:27: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in assignment
critical_section_ = new CRITICAL_SECTION;
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8880:54: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
::InitializeCriticalSection(critical_section_);
^
modules\ts\CMakeFiles\opencv_ts.dir\build.make:237: recipe for target 'modules/ts/CMakeFiles/opencv_ts.dir/src/ts_gtest.cpp.obj' failed
mingw32-make[2]: *** [modules/ts/CMakeFiles/opencv_ts.dir/src/ts_gtest.cpp.obj] Error 1
CMakeFiles\Makefile2:5379: recipe for target 'modules/ts/CMakeFiles/opencv_ts.dir/all' failed
mingw32-make[1]: *** [modules/ts/CMakeFiles/opencv_ts.dir/all] Error 2
Makefile:159: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
I also faced the same problem while trying to build OpenCV 3.2.0 using mingw32 on Windows10. I searched a bit to find a fix on Github for similar problem. It said the problem was:
MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two separate (equivalent) structs, instead of using typedef
So, you have to add another typedef GTEST_CRITICAL_SECTION for _CRITICAL_SECTION and _RTL_CRITICAL_SECTION and use this typedef for either case.
Here is what to do :
Edit "ts_gtest.h" which is inside "opencv\sources\modules\ts\include\opencv2\ts\"
Replace this line (probably line 723)
// assuming CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
// This assumption is verified by
// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
struct _RTL_CRITICAL_SECTION;
with
#if GTEST_OS_WINDOWS_MINGW
// MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two
// separate (equivalent) structs, instead of using typedef
typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#else
// Assume CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
// This assumption is verified by
// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION
typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#endif
Replace this line (probably on line 3060 before your edit - line number would have changed as you modified first part)
_RTL_CRITICAL_SECTION* critical_section_;
with
GTEST_CRITICAL_SECTION* critical_section_;
These two changes should fix your above error.
It was fixed by using TDM-gcc mingw compiler.

Cross-compiling the POCO library for OpenWRT Linux environment using the OpenWRT toolchain

I am trying to cross compile the POCO source package for OpenWRT Linux environment using the OpenWRT toolchain. I have downloaded the POCO source package and am trying to cross compile it, but I am getting the error log as below
src/Error.cpp: In static member function 'static std::string
Poco::Error::getMessage(int)': src/Error.cpp:71:55: error: invalid
conversion from 'int' to 'const char*' [-fpermissive]
return std::string(strerror_r(errorCode, errmsg, 256));
^
In file included from
/home/ubuntu/subhendu/options_cg/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.10/mips-openwrt-linux-musl/include/c++/4.8.3/string:53:0,
from include/Poco/Bugcheck.h:24,
from include/Poco/Foundation.h:148,
from src/Error.cpp:17: /home/ubuntu/subhendu/options_cg/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.10/mips-openwrt-linux-musl/include/c++/4.8.3/bits/basic_string.tcc:212:5:
error: initializing argument 1 of 'std::basic_string<_CharT,
_Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' [-fpermissive]
basic_string<_CharT, _Traits, _Alloc>::
^
/home/ubuntu/subhendu/Poco/poco-1.6.0/build/rules/compile:53: recipe for target
'/home/ubuntu/subhendu/Poco/poco-1.6.0/Foundation/obj/Linux/x86_64/debug_shared/Error.o'
failed make[1]: ***
[/home/ubuntu/subhendu/Poco/poco-1.6.0/Foundation/obj/Linux/x86_64/debug_shared/Error.o]
Error 1 make[1]: Leaving directory
'/home/ubuntu/subhendu/Poco/poco-1.6.0/Foundation' Makefile:69: recipe
for target 'Foundation-libexec' failed make: *** [Foundation-libexec]
Error 2
If anybody faced the same issue or has any idea on how to resolve it, please give your solution...
Looking at the man page for strerror_r, I see:
int strerror_r(int errnum, char *buf, size_t buflen);
/* XSI-compliant */
char *strerror_r(int errnum, char *buf, size_t buflen);
/* GNU-specific */
Note the difference in return type.
Looking at your error message:
error: invalid conversion from 'int' to 'const char*' [-fpermissive]
return std::string(strerror_r(errorCode, errmsg, 256));
^
It seems that the source you're compiling is expecting the GNU-specific version of strerror_r, but getting the XSI-compliant one. Either your target does not provide the GNU extension, or your toolchain is not set up correctly.
The man page goes on:
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
The XSI-compliant version of strerror_r() is provided if:
(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
Otherwise, the GNU-specific version is provided.
So you might want to investigate in that direction. (What is _POSIX_C_SOURCE, _XOPEN_SOURCE and _GNU_SOURCE set to when you're trying to compile?)

Make Error Compiling Armadillo 4.300.8

I am trying to compile the newest version of the Armadillo Linear Algebra library (4.300.8) and am running into the following errors when running make after cmake . runs successfully.
Scanning dependencies of target armadillo
[100%] Building CXX object CMakeFiles/armadillo.dir/src/wrapper.cpp.o
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp: In function ‘hid_t arma::arma_H5Dopen(hid_t, const char*, hid_t)’:
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp:890:43: error: too many arguments to function ‘hid_t H5Dopen1(hid_t, const char*)’
/usr/include/H5Dpublic.h:145:14: note: declared here
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp: In function ‘hid_t arma::arma_H5Dcreate(hid_t, const char*, hid_t, hid_t, hid_t, hid_t, hid_t)’:
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp:900:83: error: too many arguments to function ‘hid_t H5Dcreate1(hid_t, const char*, hid_t, hid_t, hid_t)’
/usr/include/H5Dpublic.h:143:14: note: declared here
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp: In function ‘herr_t arma::arma_H5Eset_auto(hid_t, H5E_auto1_t, void*)’:
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp:950:54: error: invalid conversion from ‘hid_t {aka int}’ to ‘H5E_auto1_t {aka int (*)(void*)}’ [-fpermissive]
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp:950:54: error: invalid conversion from ‘H5E_auto1_t {aka int (*)(void*)}’ to ‘void*’ [-fpermissive]
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp:950:54: error: too many arguments to function ‘herr_t H5Eset_auto1(H5E_auto1_t, void*)’
/usr/include/H5Epublic.h:216:15: note: declared here
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp: In function ‘herr_t arma::arma_H5Eget_auto(hid_t, herr_t (**)(void*), void**)’:
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp:955:54: error: invalid conversion from ‘hid_t {aka int}’ to ‘herr_t (**)(void*) {aka int (**)(void*)}’ [-fpermissive]
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp:955:54: error: invalid conversion from ‘herr_t (**)(void*) {aka int (**)(void*)}’ to ‘void**’ [-fpermissive]
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp:955:54: error: too many arguments to function ‘herr_t H5Eget_auto1(herr_t (**)(void*), void**)’
/usr/include/H5Epublic.h:212:15: note: declared here
make[2]: *** [CMakeFiles/armadillo.dir/src/wrapper.cpp.o] Error 1
make[1]: *** [CMakeFiles/armadillo.dir/all] Error 2
make: *** [all] Error 2
I am using gcc version 4.7.3 and running Ubuntu 12.04.
Thanks!
It looks like the HDF5 library is causing problems. Uninstall the HDF5 library, and then reinstall Armadillo.
Another option is to update your system to Ubuntu 14.04. The previous Ubuntu LTS release (12.04) is ancient by open-source standards.

Boost serialization and namespace

I'm new using Boost serialization. I'm using xml serialization and the non intrusive version. I followed the tutorial (from Boost website) step by step and my code works fine.
The problem arise when I put my class (the code is divided in .h and .cpp plus a main.cpp file) in a namespace (ns_mytests). In this case the compiler (g++) complains and I have the following errors:
g++ -c -g test.o.d -o build/Debug/GNU-Linux-x86/sources/test.o sources/test.cpp
/opt/local/include/boost/serialization/split_free.hpp: In static member function 'static void boost::serialization::free_saver<Archive, T>::invoke(Archive&, const T&, unsigned int) [with Archive = boost::archive::xml_oarchive, T = ns_mytests::Test]':
/opt/local/include/boost/serialization/split_free.hpp:74: instantiated from 'void boost::serialization::split_free(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_oarchive, T = ns_mytests::Test]'
sources/test.h:117: instantiated from 'void boost::serialization::serialize(Archive&, ns_mytests::Test&, unsigned int) [with Archive = boost::archive::xml_oarchive]'
/opt/local/include/boost/serialization/serialization.hpp:128: instantiated from 'void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_oarchive, T = ns_mytests::Test]'
/opt/local/include/boost/archive/detail/oserializer.hpp:148: instantiated from 'void boost::archive::detail::oserializer<Archive, T>::save_object_data(boost::archive::detail::basic_oarchive&, const void*) const [with Archive = boost::archive::xml_oarchive, T = ns_mytests::Test]'
sources/test.cpp:146: instantiated from here
/opt/local/include/boost/serialization/split_free.hpp:45: error: no matching function for call to 'save(boost::archive::xml_oarchive&, const ns_mytests::Test&, const boost::serialization::version_type&)'
make[2]: *** [build/Debug/GNU-Linux-x86/sources/test.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
It's sure that I'm doing wrong something, but I could't find my error.
Any help is appreciated.
Thanks,
westfork
Define the non-intrusive save in the namespace where the type to be serialized is defined.