I am trying to use boost to pass a function to QtConcurrent.
QFutureWatcher<GDALDataset> watcher;
QFuture<GDALDataset> future;
GDALDriver *poNITFDriver;
future = QtConcurrent::run(boost::bind(
&GDALDriver::CreateCopy,
poNITFDriver,
pszDstFilename,
poDataset,
FALSE,
papszOptions,
pfnProgress,
NULL
));
watcher.setFuture(future);
where poNITFDriver is the instance of the class containing the method.
What am I doing wrong here? I get the following compile errors:
error: no match for operator= in future = QtConcurrent::run(FunctionObject) with FunctionObject = boost::_bi::bind_t<GDALDataset*, boost::_mfi::mf6<GDALDataset*, GDALDriver, const char*, GDALDataset*, int, char**, int (*)(double, const char*, void*), void*>, boost::_bi::list7<boost::_bi::value<GDALDriver*>, boost::_bi::value<const char*>, boost::_bi::value<GDALDataset*>, boost::_bi::value<bool>, boost::_bi::value<char**>, boost::_bi::value<int (*)(double, const char*, void*)>, boost::_bi::value<long int> > >
Related
I'm trying to debug my opengl program. and trying to use the error logging function. glDebugMessageCallback. However the only examples i can find use "typedef void (APIENTRY *DEBUGPROC)" or void APIENTRY glDebugOutput(...). and i know APIENTRY is a windows WINAPI based compiler flag, soo, how do i write a function that will work on linux using g++ compiler?... is it even possible?
if i try to it without that i get..
error: invalid conversion from ‘void* ()(GLenum, GLenum, GLuint, GLenum, GLsizei, const GLchar, void*)’ {aka ‘void* ()(unsigned int, unsigned int, unsigned int, unsigned int, int, const char, void*)’} to ‘GLDEBUGPROC’ {aka ‘void ()(unsigned int, unsigned int, unsigned int, unsigned int, int, const char, const void*)’} [-fpermissive]
According to the OpenGL 4.6 spec, Section 20.2 Debug Message Callback
callback must be a function whose prototype is of the form
void callback( enum source, enum type, uint id,
enum severity, sizei length, const char *message,
const void *userParam );
The definition does not contain any mentioning of APIENTRY. But even if so, most gl.h files will contain a definition similar to
#define APIENTRY GLAPIENTRY
But all of this has nothing to do with your problem. The real problem you have is that your function parameter do not match the debug message callback definition. As the error message states:
void* () (unsigned int, unsigned int, unsigned int, unsigned int, int, const char, void*)
does not match
void ()(unsigned int, unsigned int, unsigned int, unsigned int, int, const char, const void*)
Basically, you are missing a const for the last parameter.
I am trying to cast TracedValue<uint32_t> m_bytesInFlight to uint32_t but I get the following error
error: cannot convert ‘ns3::TracedValue<ns3::SequenceNumber<unsigned int, int> >’ to ‘uint32_t {aka unsigned int}
Function prototype and variable declarations are
uint32_t UnAckDCount (void) const;
TracedValue<uint32_t> m_bytesInFlight {0}; //!< Bytes in flight
Here i am calling the function
uint32_t
TcpSocketBase::UnAckDCount () const
{
return m_tcb->m_highTxMark - (uint32_t) m_tcb->m_bytesInFlight;
}
Please suggest some method so that I can execute the return statement to get the result. Thanks in advance
Changing m_tcb->m_highTxMark to m_tcb->m_highTxMark.Get().GetValue() should work.
Seeing the compiler error, it's easy to figure out that variable m_highTxMark is of type ns3::TracedValue<ns3::SequenceNumber<unsigned int, int> >. I checked the documentation of ns3::TracedValue and ns3::SequenceNumber, they both have getter functions Get() and GetValue() respectively.
See:
https://www.nsnam.org/doxygen/classns3_1_1_traced_value.html
https://www.nsnam.org/doxygen/classns3_1_1_sequence_number.html
using namespace std;
vector<IDrawable*>::const_iterator itDrawable;
for(itDrawable= scene.getDrawables().begin(); itDrawable!=scene.getDrawables().end();itDrawable++){
IDrawable *drawable =(*itDrawable);
drawable->draw();
}
This code is passing me the error:
Description Resource Path Location Type no match for 'operator!='
(operand types are 'std::vector<IDrawable*>::const_iterator {aka
__gnu_cxx::__normal_iterator<IDrawable* const*, std::vector<IDrawable*> >}' and 'std::vector<const
IDrawable*>::const_iterator {aka __gnu_cxx::__normal_iterator<const
IDrawable* const*, std::vector<const IDrawable*> >}')
And
Description Resource Path Location Type no match for 'operator='
(operand types are 'std::vector<IDrawable*>::const_iterator {aka
__gnu_cxx::__normal_iterator<IDrawable* const*, std::vector<IDrawable*> >}' and 'std::vector<const
IDrawable*>::const_iterator {aka __gnu_cxx::__normal_iterator<const
IDrawable* const*, std::vector<const IDrawable*> >}')
I have looked these up and i should have something to do with the const_iterator ?
yet my scene.getDrawables() looks like:
const std::vector<const IDrawable*>& getDrawables() const {
return drawables;
}
So the iterator should be a const_iterator right ?
I have no clue what has to change...
Your
const std::vector<const IDrawable*>& getDrawables() const
returns a const reference to a vector of const IDrawable* pointers. However your
vector<IDrawable*>::const_iterator itDrawable;
declares a const_iterator to a vector of different type (IDrawable*, not const IDrawable*). Either change the definition to vector<const IDrawable*>::const_iterator itDrawable; or simply use auto to declare the iterator in your for loop,
for(auto itDrawable= scene.getDrawables().cbegin(); ...)
The formatting of your question hides the real problem, but you used:
vector<IDrawable*>::const_iterator itDrawable;
where you should have used
vector<const IDrawable*>::const_iterator iDrawable;
Likewise, you then need
const IDrawable *drawable =...
instead of
IDrawable *drawable =...
All this due to the fact that you have a std::vector<const IDrawable*>.
I want to use c++ numerical recipes on my python script but I am having some issues compiling some stuff in the Boost Python Libraries. Specificly I want to expose the amoeba function to python. I use Make rather than BJam. This is what I get when I try to compile:
costantinoagnesi#costantino-HP-Pavilion-dv5-Notebook-PC:~/Desktop/Boost Python Test$ make
g++ -I/usr/include/python2.7 -I/usr/include -fPIC -c amoeba_py.C
In file included from /usr/local/include/boost/python/object/make_instance.hpp:10:0,
from /usr/local/include/boost/python/object/make_ptr_instance.hpp:8,
from /usr/local/include/boost/python/to_python_indirect.hpp:11,
from /usr/local/include/boost/python/converter/arg_to_python.hpp:10,
from /usr/local/include/boost/python/call.hpp:15,
from /usr/local/include/boost/python/object_core.hpp:14,
from /usr/local/include/boost/python/args.hpp:25,
from /usr/local/include/boost/python.hpp:11,
from amoeba_py.C:73:
/usr/local/include/boost/python/converter/registered.hpp: In function ‘const boost::python::converter::registration&
boost::python::converter::detail::registry_lookup2(T& (*)()) [with T = double(const NRVec<double>&)]’:
/usr/local/include/boost/python/converter/registered.hpp:94:40: instantiated from ‘const >boost::python::converter::registration& boost::python::converter::detail::registry_lookup1(boost::type<T>) [with T = double (&)(const NRVec<double>&)]’
/usr/local/include/boost/python/converter/registered.hpp:105:23: instantiated from const boost::python::converter::registration& boost::python::converter::detail::registered_base<double (&)(const NRVec<double>&)>::converters’
/usr/local/include/boost/python/converter/arg_from_python.hpp:269:99: instantiated from ‘boost::python::converter::pointer_arg_from_python<T>::pointer_arg_from_python(PyObject*) [with T = double (*)(const NRVec<double>&), PyObject = _object]’
/usr/local/include/boost/python/arg_from_python.hpp:70:18: instantiated from ‘boost::python::arg_from_python<T>::arg_from_python(PyObject*) [with T = double (*)(const NRVec<double>&), PyObject = _object]’
/usr/local/include/boost/preprocessor/iteration/detail/local.hpp:43:1: instantiated from >‘PyObject* boost::python::detail::caller_arity<5u>::impl<F, Policies, Sig>::operator( (PyObject*, PyObject*) [with F = void (*)(NRMat<double>&, NRVec<double>&, double, double (*)(const NRVec<double>&), int&), Policies = boost::python::default_call_policies, Sig = boost::mpl::vector6<void, NRMat<double>&, NRVec<double>&, double, double (*)(const NRVec<double>&), int&>, PyObject = _object]’
/usr/local/include/boost/python/object/py_function.hpp:38:33: instantiated from ‘PyObject* boost::python::objects::caller_py_function_impl<Caller>::operator()(PyObject*, PyObject*) [with Caller = boost::python::detail::caller<void (*)(NRMat<double>&, NRVec<double>&, double, double (*)(const NRVec<double>&), int&), boost::python::default_call_policies, boost::mpl::vector6<void, NRMat<double>&, NRVec<double>&, double, double (*)(const NRVec<double>&), int&> >, PyObject = _object]’ amoeba_py.C:79:1: instantiated from here
/usr/local/include/boost/python/converter/registered.hpp:86:7: error: no matching function >for call to ‘register_shared_ptr1(double (*)(const NRVec<double>&))’
/usr/local/include/boost/python/converter/registered.hpp:86:7: note: candidate is:
/usr/local/include/boost/python/converter/registered.hpp:77:3: note: template<class T> void boost::python::converter::detail::register_shared_ptr1(const volatile T*)
make: *** [amoeba_py.o] Error 1
Can someone help me decipher what this error means and perhaps give me some helpful tip to finish my project. It's worth noting that the classic Boost Python example compiles just fine.
Thank you!
Here's the offending text: (lines 73-79)
#include <boost/python.hpp>
using namespace boost::python;
BOOST_PYTHON_MODULE(amoeba)
{
def("amoeba", NR::amoeba);
}
I suspect you're having a similar problem to the guy who asked this question. Are you passing a function pointer as an argument in your C++ code? If so, you can't do that in Python -- see the answer as to why.
You forgot reference operator. Thus the def is getting parameter type double (*)(const NRVec<double>&) instead of const volatile T* it expects.
Your code ought to look like this:
BOOST_PYTHON_MODULE(amoeba)
{
def("amoeba", &NR::amoeba);
}
I have a problem when compiling my code under Mac OS. This function declaration in my header file apparently causes some errors (it does work fine under Windows, though):
#include <string>
#include <vector>
#include <map>
#ifdef WIN32
#include <windows.h>
#endif
[...]
int setProcessEnvironment(
const wchar_t * procName,
const wchar_t * appName = NULL,
const wchar_t * workingDir = NULL,
const wchar_t * cmdArgs = NULL,
const std::vector< std::pair<const wchar_t *, int> > &systemEnvVars = std::vector< std::pair<const wchar_t *, int> >()
);
It looks like the compiler doesn't like the input for my pair - maybe I am missing some includes or what is the problem here?
I also don't fully understand the last line of this error message as my function description actually looks very different to the one in this error...
I am starting to think it may have to do with the default initialization, but what is the difference between the Mac and Windows compiler here?
26: error: expected ‘,’ or ‘...’ before ‘>’ token
26: error: wrong number of template arguments (1, should be 2)
/usr/include/c++/4.2.1/bits/stl_pair.h:68: error: provided for ‘template<class _T1, class _T2> struct std::pair’
26: error: template argument 1 is invalid
26: error: template argument 2 is invalid
26: error: default argument missing for parameter 6 of ‘int SysProcManager::setProcessEnvironment(const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const std::vector<std::pair<const wchar_t*, int>, std::allocator<std::pair<const wchar_t*, int> > >&, int)’
159: error: prototype for ‘int SysProcManager::setProcessEnvironment(const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const std::vector<std::pair<const wchar_t*, int>, std::allocator<std::pair<const wchar_t*, int> > >&)’ does not match any in class ‘SysProcManager’
26: error: candidates are: int SysProcManager::setProcessEnvironment(const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const std::vector<std::pair<const wchar_t*, int>, std::allocator<std::pair<const wchar_t*, int> > >&, int)
138: error: int SysProcManager::setProcessEnvironment(const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const std::vector<const wchar_t*, std::allocator<const wchar_t*> >&)
Try #include <utility>
this was pointed out by André Caron:
Out of curiosity, can you typedef
std::vector< std::pair > EnvironmentBlock;
(change the name to your liking).
Replace the two instances in your
function declaration. See if that
clears up any parsing errors.
I am now declaring typedef std::vector< std::pair<const wchar_t*, int> > EnvironmentBlock; at the beginning and it does solve this problem on the Mac and it seems the compiler just can't deal with these nested types properly and screws things up - I did not see this problem on Linux or Windows, so maybe it's time to update my compiler (GCC 4.2).
Thank you Andre!
Several of the errors relate to the fact you have 2 definitions of setProcessEnvironment. One that takes as an added int on the end and another that takes in vector of wchar_t (not a vector of pairs).
I'd focus on these 2 problems to begin with. Failing that we need to see the rest of the code because some of the errors are being generated by code we can't see.