NDK template instantiion cannot compile operator << - android-ndk

I'm using operator << on a custom class. This compiles fine in VS2017 but not in NDK.
static std::ostream & operator << (std::ostream & os, const V & v2) { return os << V.x; }
In NDK, it goes through its list of template specialization in basic_ostream and can't find it.
D:/Library/android-ndk-r16/build//../sources/cxx-stl/llvm-libc++/include\ostream:1036:10: error: invalid operands to binary expression ('std::__ndk1::basic_ostringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >' and 'const cocos2d::Vec2')
__os << __x;
D:/Library/android-ndk-r16/build//../sources/cxx-stl/llvm-libc++/include\ostream:218:20: note: candidate function not viable: no known conversion from 'const V' to 'const void *' for 1st argument; take the address of the argument with &
basic_ostream& operator<<(const void* __p);
^
D:/Library/android-ndk-r16/build//../sources/cxx-stl/llvm-libc++/include\ostream:755:1: note: candidate function not viable: no known conversion from 'const V' to 'char' for 2nd argument operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
D:/Library/android-ndk-r16/build//../sources/cxx-stl/llvm-libc++/include\ostream:788:1: note: candidate function not viable: no known conversion from 'const V' to 'char' for 2nd argument operator<<(basic_ostream<char, _Traits>& __os, char __c)
. etc

Related

error: conversion from ‘char’ to non-scalar type ‘std::string {aka std::basic_string}’ in C++

#include <iostream>
using namespace std;
int main() {
string str;
cin >> str;
string str1 = str[0]; // statement1
str1 = str[0]; // statement2
cout << str1 << endl;
}
Statement1 shows an error while statement2 runs fine. Could anyone please explain why this happens?
Statement 1 is attempting to use a constructor of std::string to initialize str1 (even though you are using an = it still calls a constructor), however there is no constructor that makes a std::string from a single character. Statement 2 on the other hand is calling std::string::operator=() of which a suitable overload for a single character exists.

Kerberos and Nodejs on mac

I have to install a project which has krb5(npm package) as a dependency but when "npm install", I'm getting this error,
./src/krb5_bind.cc:635:13: error: no matching function for call to 'krb5_get_init_creds_password'
err = krb5_get_init_creds_password(krb_context,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/krb5/krb5.h:2302:1: note: candidate function not viable: 4th
argument ('const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::value_type *'
(aka 'const char *')) would lose const qualifier
krb5_get_init_creds_password
^
../src/krb5_bind.cc:699:13: warning: 'krb5_init_context' is deprecated: use GSS.framework [-Wdeprecated-declarations]
err = krb5_init_context(&context);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/krb5/krb5.h:1434:19: note: 'krb5_init_context' has been
explicitly marked deprecated here
(krb5_context *) KERBEROS_APPLE_DEPRECATED("use GSS.framework") __API_DEPRECATED("Use GSS.framework", macos(10.0...
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/krb5/krb5.h:73:53: note: expanded from macro
'KERBEROS_APPLE_DEPRECATED'
#define KERBEROS_APPLE_DEPRECATED(x) __attribute__((deprecated(x)))
^
../src/krb5_bind.cc:750:13: warning: 'krb5_kt_resolve' is deprecated: use GSS.framework [-Wdeprecated-declarations]
err = krb5_kt_resolve(krb_context, kt_name.c_str(), &ktid);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/krb5/krb5.h:1682:19: note: 'krb5_kt_resolve' has been explicitly
marked deprecated here
krb5_keytab * ) KERBEROS_APPLE_DEPRECATED("use GSS.framework") __API_DEPRECATED("Use GSS.framework", maco...
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/krb5/krb5.h:73:53: note: expanded from macro
'KERBEROS_APPLE_DEPRECATED'
#define KERBEROS_APPLE_DEPRECATED(x) __attribute__((deprecated(x)))
^
../src/krb5_bind.cc:815:13: error: no matching function for call to 'krb5_get_init_creds_keytab'
err = krb5_get_init_creds_keytab(krb_context,
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/krb5/krb5.h:2314:1: note: candidate function not viable: 6th
argument ('const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::value_type *'
(aka 'const char *')) would lose const qualifier
krb5_get_init_creds_keytab
^
17 warnings and 2 errors generated.
I am running on mac os and I doubt that it is using the Kerberos from the Mac OS rather than taking it from the krb5 dependency.
You need to compile MIT Kerberos manual,
wget https://kerberos.org/dist/krb5/1.19/krb5-1.19.1.tar.gz
tar -xzf krb5-1.19.1.tar.gz
cd krb5-1.19.1.tar.gz/src
./configure
make
sudo make install
See: https://github.com/adaltas/node-krb5/issues/10#issuecomment-426997642

error: 'SetPosition' was not declared in this scope

Arduino: 1.6.9 (Windows 10), Board: "Arduino Mega ADK"
In file included from C:\Users\Disheet\Downloads\humanoid_1\humanoid_1.ino:1:0:
C:\Users\Disheet\Documents\Arduino\libraries\ax12v2/ax12.h:66:23: error: conflicting declaration 'typedef unsigned char boolean'
typedef unsigned char boolean;
^
In file included from sketch\humanoid_1.ino.cpp:1:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:117:14: error: 'boolean' has a previous declaration as 'typedef bool boolean'
typedef bool boolean;
^
C:\Users\Disheet\Downloads\humanoid_1\humanoid_1.ino: In function 'void setup()':
humanoid_1:5: error: 'SetPosition' was not declared in this scope
SetPosition(1,0);////id,posiotin 0-1023
^
C:\Users\Disheet\Downloads\humanoid_1\humanoid_1.ino: In function 'void loop()':
humanoid_1:13: error: 'SetPosition' was not declared in this scope
SetPosition(1,512);
^
Multiple libraries were found for "ax12.h"
Used: C:\Users\Disheet\Documents\Arduino\libraries\ax12v2
Not used: C:\Users\Disheet\Documents\Arduino\libraries\Bioloid
exit status 1
'SetPosition' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
You'll need to find typedef unsigned char boolean; in your library and change it to match the version in Arduino.h.
boolean is already a typedef in Arduino.h, and it is a bool ,not unsigned char.
In the AX12 library search for this:
https://github.com/7Robot/Arduino/blob/master/AX12/libraries/ax12/ax12.h#L66
And change it to typedef bool boolean;.
This was updated a while ago, so your IDE version is newer than the AX12 library.

How do you post a boost packaged_task to an io_service in C++03?

This is a follow-on from a previous question (here), but I'm working on a multithreaded application and I would like to post a Boost packaged_task to a threaded io_service. I'm stuck using a C++03 compiler (so std::move is out), and the packaged_task is not copyable. I've tried wrapping it in a shared_ptr and passing that, and a lot of other things. Here is my current attempt and the subsequent compiler errors. Any idea how to get this to work?
boost::asio::io_service io_service;
boost::thread_group threads;
boost::asio::io_service::work work(io_service);
for (int i = 0; i < maxNumThreads; ++i)
{
threads.create_thread(boost::bind(&boost::asio::io_service::run,
&io_service));
}
std::vector<boost::shared_future<bool> > pending_data; // vector of futures
bool process_data(int,int){...}
...
for(int theTime = 0; theTime != totalScenarioTime; ++theTime)
{
for(int i = 0; i < numSmallTasks; ++i)
{
boost::packaged_task<bool> task(boost::bind(&process_data,i,theTime));
boost::shared_future<bool> fut(task.get_future());
pending_data.push_back(fut); // C++11 possible: (std::move(fut) when fut is a unique_future);
io_service.post(task); // C++11 possible: (std::move(task));
}
// After loop - wait until all futures are evaluated
boost::wait_for_all(pending_data.begin(), pending_data.end());
pending_data.clear();
}
This results in:
In file included from ../boostlibs/boost/asio/io_service.hpp:767:0,
from ../boostlibs/boost/asio/basic_io_object.hpp:19,
from ../boostlibs/boost/asio/basic_socket.hpp:19,
from ../boostlibs/boost/asio/basic_datagram_socket.hpp:20,
from ../boostlibs/boost/asio.hpp:20,
from ../main.cpp:13:
../boostlibs/boost/asio/impl/io_service.hpp: In member function ‘void boost::asio::io_service::post(const CompletionHandler&) [with CompletionHandler = boost::packaged_task<bool>]’:
../main.cpp:256:23: instantiated from here
../boostlibs/boost/asio/impl/io_service.hpp:95:67: error: no matching function for call to ‘boost::packaged_task<bool>::packaged_task(const boost::packaged_task<bool>&)’
../boostlibs/boost/asio/impl/io_service.hpp:95:67: note: candidates are:
../boostlibs/boost/thread/future.hpp:1372:9: note: boost::packaged_task<R>::packaged_task(boost::detail::thread_move_t<boost::packaged_task<R> >) [with R = bool]
../boostlibs/boost/thread/future.hpp:1372:9: note: no known conversion for argument 1 from ‘const boost::packaged_task<bool>’ to ‘boost::detail::thread_move_t<boost::packaged_task<bool> >’
../boostlibs/boost/thread/future.hpp:1318:9: note: boost::packaged_task<R>::packaged_task() [with R = bool]
../boostlibs/boost/thread/future.hpp:1318:9: note: candidate expects 0 arguments, 1 provided
../boostlibs/boost/thread/future.hpp:1314:9: note: boost::packaged_task<R>::packaged_task(boost::packaged_task<R>&) [with R = bool, boost::packaged_task<R> = boost::packaged_task<bool>]
../boostlibs/boost/thread/future.hpp:1314:9: note: no known conversion for argument 1 from ‘const boost::packaged_task<bool>’ to ‘boost::packaged_task<bool>&’
../boostlibs/boost/asio/detail/handler_type_requirements.hpp:95:26: error: initializing argument 1 of ‘T& boost::asio::detail::lvref(T) [with T = boost::packaged_task<bool>]’
../boostlibs/boost/asio/impl/io_service.hpp:95:67: error: no matching function for call to ‘boost::packaged_task<bool>::packaged_task(const boost::packaged_task<bool>&)’
../boostlibs/boost/asio/impl/io_service.hpp:95:67: note: candidates are:
../boostlibs/boost/thread/future.hpp:1372:9: note: boost::packaged_task<R>::packaged_task(boost::detail::thread_move_t<boost::packaged_task<R> >) [with R = bool]
../boostlibs/boost/thread/future.hpp:1372:9: note: no known conversion for argument 1 from ‘const boost::packaged_task<bool>’ to ‘boost::detail::thread_move_t<boost::packaged_task<bool> >’
../boostlibs/boost/thread/future.hpp:1318:9: note: boost::packaged_task<R>::packaged_task() [with R = bool]
../boostlibs/boost/thread/future.hpp:1318:9: note: candidate expects 0 arguments, 1 provided
../boostlibs/boost/thread/future.hpp:1314:9: note: boost::packaged_task<R>::packaged_task(boost::packaged_task<R>&) [with R = bool, boost::packaged_task<R> = boost::packaged_task<bool>]
../boostlibs/boost/thread/future.hpp:1314:9: note: no known conversion for argument 1 from ‘const boost::packaged_task<bool>’ to ‘boost::packaged_task<bool>&’
../boostlibs/boost/asio/detail/handler_type_requirements.hpp:96:32: error: initializing argument 1 of ‘const T& boost::asio::detail::clvref(T) [with T = boost::packaged_task<bool>]’
../boostlibs/boost/asio/impl/io_service.hpp:97:3: error: no matching function for call to ‘boost::packaged_task<bool>::packaged_task(const boost::packaged_task<bool>&)’
../boostlibs/boost/asio/impl/io_service.hpp:97:3: note: candidates are:
../boostlibs/boost/thread/future.hpp:1372:9: note: boost::packaged_task<R>::packaged_task(boost::detail::thread_move_t<boost::packaged_task<R> >) [with R = bool]
../boostlibs/boost/thread/future.hpp:1372:9: note: no known conversion for argument 1 from ‘const boost::packaged_task<bool>’ to ‘boost::detail::thread_move_t<boost::packaged_task<bool> >’
../boostlibs/boost/thread/future.hpp:1318:9: note: boost::packaged_task<R>::packaged_task() [with R = bool]
../boostlibs/boost/thread/future.hpp:1318:9: note: candidate expects 0 arguments, 1 provided
../boostlibs/boost/thread/future.hpp:1314:9: note: boost::packaged_task<R>::packaged_task(boost::packaged_task<R>&) [with R = bool, boost::packaged_task<R> = boost::packaged_task<bool>]
../boostlibs/boost/thread/future.hpp:1314:9: note: no known conversion for argument 1 from ‘const boost::packaged_task<bool>’ to ‘boost::packaged_task<bool>&’
../boostlibs/boost/asio/detail/impl/task_io_service.hpp:54:6: error: initializing argument 1 of ‘void boost::asio::detail::task_io_service::post(Handler) [with Handler = boost::packaged_task<bool>]’
Using boost::move(task) results in the two errors:
error: no match for call to ‘(boost::detail::thread_move_t<boost::packaged_task<bool> >) ()’
error: no match for call to ‘(boost::detail::thread_move_t<boost::packaged_task<bool> >) ()’
boost::packaged_task supports boost::move since Boost version 1.50, see corresponding ticket.
But the problem is that io_service::post completion handler parameter must be CopyConstructible as noted in Asio handler requirements. Therefore boost::packaged_task cannot be posted directly or by moving. (Thanks to Igor R. for this issue).
There is workaround using pointers, e.g. you could wrap boost::packaged_task with boost::shared_ptr and bind it to operator():
typedef boost::packaged_task<bool> task_t;
boost::shared_ptr<task_t> task = boost::make_shared<task_t>(
boost::bind(&process_data, i, theTime));
io_service.post(boost::bind(&task_t::operator(), task));

cannot convert parameter 1 from 'ATL::CString' to 'const wchar_t *'

For this line of code:
int currentSnapshotHeight = _wtoi(ExecuteExternalProgram(L"current.png"));
I got this error:
Error 1 error C2664: '_wtoi' : cannot convert parameter 1 from 'ATL::CString' to 'const wchar_t *'
How to fix?
Maybe this will work?
int currentSnapshotHeight = _wtoi(ExecuteExternalProgram(_T("current.png")));
Also check if Unicode setting of project are set as expected.
Try this:
int currentSnapshotHeight = _wtoi((wchar_t*)ExecuteExternalProgram(L"current.png").GetBuffer());

Resources