OpenCV error when running make CentOS - opencv

I am trying to install OpenCV 2.4.2 on CentOS 5.8 but I get the following error
[ 34%] Built target opencv_test_highgui
[ 34%] Building CXX object modules/features2d/CMakeFiles/opencv_features2d.dir/src/freak.cpp.o
/home/jtrinidad/Downloads/OpenCV-2.4.2/modules/core/include/opencv2/core/core.hpp:1286: warning: ‘class cv::_InputArray’ has virtual functions but non-virtual destructor
/home/jtrinidad/Downloads/OpenCV-2.4.2/modules/core/include/opencv2/core/core.hpp:1365: warning: ‘class cv::_OutputArray’ has virtual functions but non-virtual destructor
/home/jtrinidad/Downloads/OpenCV-2.4.2/modules/features2d/src/freak.cpp: In member function ‘virtual void cv::FREAK::computeImpl(const cv::Mat&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat&) const’:
/home/jtrinidad/Downloads/OpenCV-2.4.2/modules/features2d/src/freak.cpp:367: error: shift must be an immediate
make[2]: *** [modules/features2d/CMakeFiles/opencv_features2d.dir/src/freak.cpp.o] Error 1
make[1]: *** [modules/features2d/CMakeFiles/opencv_features2d.dir/all] Error 2
make: *** [all] Error 2
I ran the following command on cmake
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_EXAMPLES=OFF WITH_CUDA=OFF ..
Thank you.

The problem was resolved.
I applied the following patch to ~/Downloads/OpenCV-2.4.2/modules/features2d/src/freak.cpp
diff -crB OpenCV-2.4.2.orig/modules/features2d/src/freak.cpp OpenCV-2.4.2/modules/features2d/src/freak.cpp
*** OpenCV-2.4.2.orig/modules/features2d/src/freak.cpp 2012-07-25 09:54:50.000000000 -0400
--- OpenCV-2.4.2/modules/features2d/src/freak.cpp 2012-07-24 10:34:57.000000000 -0400
***************
*** 364,370 ****
__m128i workReg = _mm_min_epu8(operand1, operand2); // emulated "not less than" for 8-bit UNSIGNED integers
workReg = _mm_cmpeq_epi8(workReg, operand2); // emulated "not less than" for 8-bit UNSIGNED integers
! workReg = _mm_and_si128(_mm_srli_epi16(binMask, m), workReg); // merge the last 16 bits with the 128bits std::vector until full
result128 = _mm_or_si128(result128, workReg);
}
(*ptr) = result128;
--- 364,404 ----
__m128i workReg = _mm_min_epu8(operand1, operand2); // emulated "not less than" for 8-bit UNSIGNED integers
workReg = _mm_cmpeq_epi8(workReg, operand2); // emulated "not less than" for 8-bit UNSIGNED integers
! // merge the last 16 bits with the 128bits std::vector until full
! __m128i shiftedMask;
! switch(m) {
! case 8:
! shiftedMask = _mm_srli_epi16(binMask, 8);
! break;
! case 7:
! shiftedMask = _mm_srli_epi16(binMask, 7);
! break;
! case 6:
! shiftedMask = _mm_srli_epi16(binMask, 6);
! break;
! case 5:
! shiftedMask = _mm_srli_epi16(binMask, 5);
! break;
! case 4:
! shiftedMask = _mm_srli_epi16(binMask, 4);
! break;
! case 3:
! shiftedMask = _mm_srli_epi16(binMask, 3);
! break;
! case 2:
! shiftedMask = _mm_srli_epi16(binMask, 2);
! break;
! case 1:
! shiftedMask = _mm_srli_epi16(binMask, 1);
! break;
! case 0:
! shiftedMask = _mm_srli_epi16(binMask, 0);
! break;
! default:
! throw "shifting less than 0";
! }
! workReg = _mm_and_si128(shiftedMask, workReg);
!
result128 = _mm_or_si128(result128, workReg);
}
(*ptr) = result128;

This full patch file: http://code.opencv.org/projects/opencv/repository/revisions/65f85856306575e4d71164c8212e84d26424cf0f

After trying to use patches, I resorted to compile freak.cpp manually. My notes on the installation are available here: http://www.megalinux.net/compiling-opencv-2-4-on-rhelcentos-5/

Related

clang not generating debug symbols

I have a a.c
#include <stdio.h>
int main() {
int a = 1;
int b = 2;
int c = a + b;
return 0;
}
when compiling with clang -g a.c, I can't get debug symbols.
joey#voyager-arch /t/a4> lldb a.out
(lldb) target create "a.out"
Current executable set to '/tmp/a4/a.out' (x86_64).
(lldb) l
(lldb)
But if I use gcc, I can successfully got the debug symbols, compile with gcc -g a.c
joey#voyager-arch /t/a4> gdb a.out
GNU gdb (GDB) 11.1
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...
(gdb) l
1 #include <stdio.h>
2
3 int main() {
4 int a = 1;
5 int b = 2;
6 int c = a + b;
7 return 0;
8 }
(gdb)
I'm using archlinux with amd ryzen 7 cpu.
clang: 12.0.1
lldb: 12.0.1
gcc: 11.1.0
gdb: 11.1
May be a lldb 12 incompatible bug, downgrade to lldb 10 solved this problem.

install error for nmatrix gem in windows 8

I am trying to install the nmatrix gem. i have the gcc compiler installed:
C:\dev\DNA>gcc --version
gcc (GCC) 4.9.3
Copyright (C) 2015 Free Software Foundation, Inc.
then I have the following error on install:
C:\dev\DNA>gem install nmatrix
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing nmatrix:
ERROR: Failed to build gem native extension.
C:/Ruby21/bin/ruby.exe extconf.rb
using C++ standard... c++11
g++ reports version... 4.7.2
checking for rb_array_const_ptr() in ruby.h... no
checking for FIX_CONST_VALUE_PTR in ruby.h... no
checking for RARRAY_CONST_PTR in ruby.h... yes
checking for RARRAY_AREF in ruby.h... yes
creating nmatrix_config.h
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
generating nmatrix-i386-mingw32.def
compiling nmatrix.cpp
In file included from ./storage/storage.h:48:0,
from util/io.h:38,
from nmatrix.cpp:46:
./storage/common.h:155:3: error: 'u_int8_t' has not been declared
./storage/common.h:157:3: error: redefinition of 'VALUE nm::ew_op_switch(LDType,
RDType) [with nm::ewop_t op = (nm::ewop_t)3u; LDType = signed char; RDType = in
t; VALUE = long unsigned int]'
./storage/common.h:155:3: error: 'VALUE nm::ew_op_switch(LDType, RDType) [with n
m::ewop_t op = (nm::ewop_t)3u; LDType = signed char; RDType = int; VALUE = long
unsigned int]' previously declared here
./storage/common.h:165:3: error: 'u_int8_t' has not been declared
./storage/common.h:167:3: error: redefinition of 'VALUE nm::ew_op_switch(LDType,
RDType) [with nm::ewop_t op = (nm::ewop_t)3u; LDType = float; RDType = int; VAL
UE = long unsigned int]'
./storage/common.h:165:3: error: 'VALUE nm::ew_op_switch(LDType, RDType) [with n
m::ewop_t op = (nm::ewop_t)3u; LDType = float; RDType = int; VALUE = long unsign
ed int]' previously declared here
./storage/common.h:170:3: error: 'u_int8_t' has not been declared
./storage/common.h:172:3: error: redefinition of 'VALUE nm::ew_op_switch(LDType,
RDType) [with nm::ewop_t op = (nm::ewop_t)3u; LDType = double; RDType = int; VA
LUE = long unsigned int]'
./storage/common.h:170:3: error: 'VALUE nm::ew_op_switch(LDType, RDType) [with n
m::ewop_t op = (nm::ewop_t)3u; LDType = double; RDType = int; VALUE = long unsig
ned int]' previously declared here
In file included from nmatrix.cpp:283:0:
ruby_nmatrix.c: In function 'VALUE nm_reshape_bang(VALUE, VALUE)':
ruby_nmatrix.c:1102:11: warning: unused variable 'elem' [-Wunused-variable]
ruby_nmatrix.c: In function 'VALUE nm_mset(int, VALUE*, VALUE)':
ruby_nmatrix.c:2013:109: warning: format '%lu' expects argument of type 'long un
signed int', but argument 4 has type 'size_t {aka unsigned int}' [-Wformat]
ruby_nmatrix.c: In function 'VALUE nm_xslice(int, VALUE*, void* (*)(const STORAG
E*, SLICE*), void (*)(NMATRIX*), VALUE)':
ruby_nmatrix.c:2251:92: warning: format '%lu' expects argument of type 'long uns
igned int', but argument 4 has type 'size_t {aka unsigned int}' [-Wformat]
ruby_nmatrix.c: In function 'SLICE* get_slice(size_t, int, VALUE*, size_t*)':
ruby_nmatrix.c:2729:106: warning: format '%lu' expects argument of type 'long un
signed int', but argument 3 has type 'size_t {aka unsigned int}' [-Wformat]
ruby_nmatrix.c:2729:106: warning: format '%lu' expects argument of type 'long un
signed int', but argument 4 has type 'size_t {aka unsigned int}' [-Wformat]
ruby_nmatrix.c: In function 'void* interpret_initial_value(VALUE, nm::dtype_t)':
ruby_nmatrix.c:2800:29: warning: comparison between signed and unsigned integer
expressions [-Wsign-compare]
make: *** [nmatrix.o] Error 1
make failed, exit code 2
Gem files will remain installed in C:/Ruby21/lib/ruby/gems/2.1.0/gems/nmatrix-0.
2.1 for inspection.
Results logged to C:/Ruby21/lib/ruby/gems/2.1.0/extensions/x86-mingw32/2.1.0/nma
trix-0.2.1/gem_make.out
Would be really great to try out this library! Any ideas how to make the install succesful? thanks

Cannot install uwsgi on Alpine

I'm trying to install uwsgi using pip install uwsgi in my Alpine docker image but unfortunately it keeps failing weird no real error message to me:
Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-mEZegv/uwsgi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-c7XA_e-record/install-record.txt --single-version-externally-managed --compile:
running install
using profile: buildconf/default.ini
detected include path: ['/usr/include/fortify', '/usr/include', '/usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/include']
Patching "bin_name" to properly install_scripts dir
detected CPU cores: 1
configured CFLAGS: -O2 -I. -Wall -Werror -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fno-strict-aliasing -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -DUWSGI_HAS_IFADDRS -DUWSGI_ZLIB -DUWSGI_LOCK_USE_MUTEX -DUWSGI_EVENT_USE_EPOLL -DUWSGI_EVENT_TIMER_USE_TIMERFD -DUWSGI_EVENT_FILEMONITOR_USE_INOTIFY -DUWSGI_VERSION="\"2.0.12\"" -DUWSGI_VERSION_BASE="2" -DUWSGI_VERSION_MAJOR="0" -DUWSGI_VERSION_MINOR="12" -DUWSGI_VERSION_REVISION="0" -DUWSGI_VERSION_CUSTOM="\"\"" -DUWSGI_YAML -DUWSGI_PLUGIN_DIR="\".\"" -DUWSGI_DECLARE_EMBEDDED_PLUGINS="UDEP(python);UDEP(gevent);UDEP(ping);UDEP(cache);UDEP(nagios);UDEP(rrdtool);UDEP(carbon);UDEP(rpc);UDEP(corerouter);UDEP(fastrouter);UDEP(http);UDEP(ugreen);UDEP(signal);UDEP(syslog);UDEP(rsyslog);UDEP(logsocket);UDEP(router_uwsgi);UDEP(router_redirect);UDEP(router_basicauth);UDEP(zergpool);UDEP(redislog);UDEP(mongodblog);UDEP(router_rewrite);UDEP(router_http);UDEP(logfile);UDEP(router_cache);UDEP(rawrouter);UDEP(router_static);UDEP(sslrouter);UDEP(spooler);UDEP(cheaper_busyness);UDEP(symcall);UDEP(transformation_tofile);UDEP(transformation_gzip);UDEP(transformation_chunked);UDEP(transformation_offload);UDEP(router_memcached);UDEP(router_redis);UDEP(router_hash);UDEP(router_expires);UDEP(router_metrics);UDEP(transformation_template);UDEP(stats_pusher_socket);" -DUWSGI_LOAD_EMBEDDED_PLUGINS="ULEP(python);ULEP(gevent);ULEP(ping);ULEP(cache);ULEP(nagios);ULEP(rrdtool);ULEP(carbon);ULEP(rpc);ULEP(corerouter);ULEP(fastrouter);ULEP(http);ULEP(ugreen);ULEP(signal);ULEP(syslog);ULEP(rsyslog);ULEP(logsocket);ULEP(router_uwsgi);ULEP(router_redirect);ULEP(router_basicauth);ULEP(zergpool);ULEP(redislog);ULEP(mongodblog);ULEP(router_rewrite);ULEP(router_http);ULEP(logfile);ULEP(router_cache);ULEP(rawrouter);ULEP(router_static);ULEP(sslrouter);ULEP(spooler);ULEP(cheaper_busyness);ULEP(symcall);ULEP(transformation_tofile);ULEP(transformation_gzip);ULEP(transformation_chunked);ULEP(transformation_offload);ULEP(router_memcached);ULEP(router_redis);ULEP(router_hash);ULEP(router_expires);ULEP(router_metrics);ULEP(transformation_template);ULEP(stats_pusher_socket);"core/utils.c: In function 'uwsgi_as_root':
core/utils.c:344:7: error: implicit declaration of function 'unshare' [-Werror=implicit-function-declaration]
if (unshare(uwsgi.unshare)) {
^
core/utils.c:564:5: error: implicit declaration of function 'sigfillset' [-Werror=implicit-function-declaration]
sigfillset(&smask);
^
core/utils.c:565:5: error: implicit declaration of function 'sigprocmask' [-Werror=implicit-function-declaration]
sigprocmask(SIG_BLOCK, &smask, NULL);
^
core/utils.c:565:17: error: 'SIG_BLOCK' undeclared (first use in this function)
sigprocmask(SIG_BLOCK, &smask, NULL);
^
core/utils.c:565:17: note: each undeclared identifier is reported only once for each function it appears in
core/utils.c:586:7: error: implicit declaration of function 'chroot' [-Werror=implicit-function-declaration]
if (chroot(uwsgi.chroot)) {
^
core/utils.c:791:5: error: unknown type name 'ushort'
ushort *array;
^
core/utils.c:833:8: error: implicit declaration of function 'setgroups' [-Werror=implicit-function-declaration]
if (setgroups(0, NULL)) {
^
core/utils.c:848:8: error: implicit declaration of function 'initgroups' [-Werror=implicit-function-declaration]
if (initgroups(uidname, uwsgi.gid)) {
^
core/utils.c: In function 'uwsgi_close_request':
core/utils.c:1145:18: error: 'WAIT_ANY' undeclared (first use in this function)
while (waitpid(WAIT_ANY, &waitpid_status, WNOHANG) > 0);
^
core/utils.c: In function 'uwsgi_resolve_ip':
core/utils.c:1802:7: error: implicit declaration of function 'gethostbyname' [-Werror=implicit-function-declaration]
he = gethostbyname(domain);
^
core/utils.c:1802:5: error: assignment makes pointer from integer without a cast [-Werror=int-conversion]
he = gethostbyname(domain);
^
core/utils.c: In function 'uwsgi_unix_signal':
core/utils.c:1936:19: error: storage size of 'sa' isn't known
struct sigaction sa;
^
core/utils.c:1938:24: error: invalid application of 'sizeof' to incomplete type 'struct sigaction'
memset(&sa, 0, sizeof(struct sigaction));
^
core/utils.c:1942:2: error: implicit declaration of function 'sigemptyset' [-Werror=implicit-function-declaration]
sigemptyset(&sa.sa_mask);
^
core/utils.c:1944:6: error: implicit declaration of function 'sigaction' [-Werror=implicit-function-declaration]
if (sigaction(signum, &sa, NULL) < 0) {
^
core/utils.c:1936:19: error: unused variable 'sa' [-Werror=unused-variable]
struct sigaction sa;
^
In file included from core/utils.c:1:0:
core/utils.c: In function 'uwsgi_list_has_num':
./uwsgi.h:140:47: error: implicit declaration of function 'strtok_r' [-Werror=implicit-function-declaration]
#define uwsgi_foreach_token(x, y, z, w) for(z=strtok_r(x, y, &w);z;z = strtok_r(NULL, y, &w))
^
core/utils.c:1953:2: note: in expansion of macro 'uwsgi_foreach_token'
uwsgi_foreach_token(list2, ",", p, ctx) {
^
./uwsgi.h:140:46: error: assignment makes pointer from integer without a cast [-Werror=int-conversion]
#define uwsgi_foreach_token(x, y, z, w) for(z=strtok_r(x, y, &w);z;z = strtok_r(NULL, y, &w))
^
core/utils.c:1953:2: note: in expansion of macro 'uwsgi_foreach_token'
uwsgi_foreach_token(list2, ",", p, ctx) {
^
./uwsgi.h:140:70: error: assignment makes pointer from integer without a cast [-Werror=int-conversion]
#define uwsgi_foreach_token(x, y, z, w) for(z=strtok_r(x, y, &w);z;z = strtok_r(NULL, y, &w))
^
core/utils.c:1953:2: note: in expansion of macro 'uwsgi_foreach_token'
uwsgi_foreach_token(list2, ",", p, ctx) {
^
core/utils.c: In function 'uwsgi_list_has_str':
./uwsgi.h:140:46: error: assignment makes pointer from integer without a cast [-Werror=int-conversion]
#define uwsgi_foreach_token(x, y, z, w) for(z=strtok_r(x, y, &w);z;z = strtok_r(NULL, y, &w))
^
core/utils.c:1968:2: note: in expansion of macro 'uwsgi_foreach_token'
uwsgi_foreach_token(list2, " ", p, ctx) {
^
./uwsgi.h:140:70: error: assignment makes pointer from integer without a cast [-Werror=int-conversion]
#define uwsgi_foreach_token(x, y, z, w) for(z=strtok_r(x, y, &w);z;z = strtok_r(NULL, y, &w))
^
core/utils.c:1968:2: note: in expansion of macro 'uwsgi_foreach_token'
uwsgi_foreach_token(list2, " ", p, ctx) {
^
core/utils.c:1969:8: error: implicit declaration of function 'strcasecmp' [-Werror=implicit-function-declaration]
if (!strcasecmp(p, str)) {
^
core/utils.c: In function 'uwsgi_sig_pause':
core/utils.c:2361:2: error: implicit declaration of function 'sigsuspend' [-Werror=implicit-function-declaration]
sigsuspend(&mask);
^
core/utils.c: In function 'uwsgi_run_command_putenv_and_wait':
core/utils.c:2453:7: error: implicit declaration of function 'putenv' [-Werror=implicit-function-declaration]
if (putenv(envs[i])) {
^
In file included from core/utils.c:1:0:
core/utils.c: In function 'uwsgi_build_unshare':
./uwsgi.h:140:46: error: assignment makes pointer from integer without a cast [-Werror=int-conversion]
#define uwsgi_foreach_token(x, y, z, w) for(z=strtok_r(x, y, &w);z;z = strtok_r(NULL, y, &w))
^
core/utils.c:2855:2: note: in expansion of macro 'uwsgi_foreach_token'
uwsgi_foreach_token(list, ",", p, ctx) {
^
./uwsgi.h:140:70: error: assignment makes pointer from integer without a cast [-Werror=int-conversion]
#define uwsgi_foreach_token(x, y, z, w) for(z=strtok_r(x, y, &w);z;z = strtok_r(NULL, y, &w))
^
core/utils.c:2855:2: note: in expansion of macro 'uwsgi_foreach_token'
uwsgi_foreach_token(list, ",", p, ctx) {
^
core/utils.c: In function 'uwsgi_tmpfd':
core/utils.c:3533:7: error: implicit declaration of function 'mkstemp' [-Werror=implicit-function-declaration]
fd = mkstemp(template);
^
core/utils.c: In function 'uwsgi_expand_path':
core/utils.c:3615:7: error: implicit declaration of function 'realpath' [-Werror=implicit-function-declaration]
if (!realpath(src, dst)) {
^
core/utils.c: In function 'uwsgi_set_cpu_affinity':
core/utils.c:3641:3: error: unknown type name 'cpu_set_t'
cpu_set_t cpuset;
^
core/utils.c:3646:3: error: implicit declaration of function 'CPU_ZERO' [-Werror=implicit-function-declaration]
CPU_ZERO(&cpuset);
^
core/utils.c:3651:4: error: implicit declaration of function 'CPU_SET' [-Werror=implicit-function-declaration]
CPU_SET(base_cpu, &cpuset);
^
core/utils.c:3662:7: error: implicit declaration of function 'sched_setaffinity' [-Werror=implicit-function-declaration]
if (sched_setaffinity(0, sizeof(cpu_set_t), &cpuset)) {
^
core/utils.c:3662:35: error: 'cpu_set_t' undeclared (first use in this function)
if (sched_setaffinity(0, sizeof(cpu_set_t), &cpuset)) {
^
core/utils.c: In function 'uwsgi_thread_run':
core/utils.c:3782:2: error: implicit declaration of function 'pthread_sigmask' [-Werror=implicit-function-declaration]
pthread_sigmask(SIG_BLOCK, &smask, NULL);
^
core/utils.c:3782:18: error: 'SIG_BLOCK' undeclared (first use in this function)
pthread_sigmask(SIG_BLOCK, &smask, NULL);
^
core/utils.c: In function 'uwsgi_envdir':
core/utils.c:4349:8: error: implicit declaration of function 'unsetenv' [-Werror=implicit-function-declaration]
if (unsetenv(de->d_name)) {
^
core/utils.c:4380:7: error: implicit declaration of function 'setenv' [-Werror=implicit-function-declaration]
if (setenv(de->d_name, content, 1)) {
^
cc1: all warnings being treated as errors
*** uWSGI compiling server core ***
Any idea what could cause this? I'm installing the following dependencies beforehand:
RUN apk --update add \
bash \
python \
python-dev \
py-pip \
gcc \
zlib-dev \
git \
linux-headers \
build-base \
musl \
musl-dev \
memcached \
libmemcached-dev
I found this on a GitHub thread. Modified it a bit and works perfectly fine for me on Python 3.5
apk add python3-dev build-base linux-headers pcre-dev
pip install uwsgi
Unfortunately the latest release of uwsgi does not support musl, a glibc alternative that alpine and a couple other distros use. Uwsgi will not build with musl when the ugreen plugin is included (see https://github.com/unbit/uwsgi/pull/522), so you still cannot pip install uwsgi. However, if you build uwsgi with the environment variable UWSGI_PROFILE=corethe build should succeed; but if will fail at runtime due to the issues solved here (https://github.com/unbit/uwsgi/pull/1210). This probably grim news -- I know it was for me -- but at least it looks like the uwsgi team is taking time to address its issues running on musl. Hopefully it will work in the next release.
This is a bit old and this was not exactly the case of the OP. In my case upgrading the version on requirements.txt to uwsgi==2.0.17.1 worked, as I found here.
have you tried
http://github.com/unbit/uwsgi/archive/uwsgi-2.0.zip
in your requirements.txt ?
you'll need the pcre-dev package installed
Upgrading uWSGI from 2.0.14 to 2.0.19.1 did the trick for me.

mprotect errno 22 iOS

I'm developing a jailbroken app on iOS and getting errno 22 when calling
mprotect(p, 1024, PROT_READ | PROT_EXEC)
errno 22 means invalid arguments but I can't figure out whats wrong. I've aligned p to be a multiple of page size, and I've malloced the memory previously before calling mprotect.
Here's my code and sample output
#define PAGESIZE 4096
FILE * pFile;
pFile = fopen ("log.txt","w");
uint32_t code[] = {
0xe2800001, // add r0, r0, #1
0xe12fff1e, // bx lr
};
fprintf(pFile, "Before Execution\n");
p = (uint32_t *)malloc(1024+PAGESIZE-1);
if (!p) {
fprintf(pFile, "Couldn't malloc(1024)");
perror("Couldn't malloc(1024)");
exit(errno);
}
fprintf(pFile, "Malloced to %p\n", p);
p = (uint32_t *)(((uintptr_t)p + PAGESIZE-1) & ~(PAGESIZE-1));
fprintf(pFile, "Moved pointer to %p\n", p);
fprintf(pFile, "Before Compiling\n");
// copy instructions to function
p[0] = code[0];
p[1] = code[1];
fprintf(pFile, "After Compiling\n");
if (mprotect(p, 1024, PROT_READ | PROT_EXEC)) {
int err = errno;
fprintf(pFile, "Couldn't mprotect2: %i\n", errno);
perror("Couldn't mprotect");
exit(errno);
}
And output:
Before Execution
Malloced to 0x13611ec00
Moved pointer 0x13611f000
Before Compiling
After Compiling
Couldn't mprotect2: 22
Fixed this by using posix_memalign(). Turns out I wasn't aligning my pointer to the page size correctly

ROS Custom message with sensor_msgs/Image Publisher

I have a custom .msg file MyImage.msg
sensor_msgs/Image im
float32 age
string name
I have configured the custom .msg fle as illustrated in link:CreatingMsgAndSrv
Further, I am trying to write a simple publisher with this msg.
#include <ros/ros.h>
#include <custom_msg/MyImage.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <cv_bridge/cv_bridge.h>
int main( int argc, char ** argv )
{
ros::init(argc, argv, "publish_custom");
ros::NodeHandle nh;
ros::Publisher pub2 = nh.advertise<custom_msg::MyImage>("custom_image", 2 );
cv::Mat image = cv::imread( "Lenna.png", CV_LOAD_IMAGE_COLOR );
sensor_msgs::ImagePtr im_msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image).toImageMsg();
ros::Rate rate( 2 );
while( ros::ok() )
{
ROS_INFO_STREAM_ONCE( "IN main loop");
custom_msg::MyImage msg2;
msg2.age=54.3;
msg2.im = im_msg;
msg2.name="Gena";
pub2.publish(msg2);
rate.sleep();
}
}
This does not seem to compile with catkin_make. The error messages are -
/home/eeuser/ros_workspaces/HeloRosProject/src/custom_msg/publish.cpp: In function ‘int main(int, char**)’:
/home/eeuser/ros_workspaces/HeloRosProject/src/custom_msg/publish.cpp:40:19: error: no match for ‘operator=’ in ‘msg2.custom_msg::MyImage_<std::allocator<void> >::im = im_msg’
/home/eeuser/ros_workspaces/HeloRosProject/src/custom_msg/publish.cpp:40:19: note: candidate is:
/opt/ros/hydro/include/sensor_msgs/Image.h:56:8: note: sensor_msgs::Image_<std::allocator<void> >& sensor_msgs::Image_<std::allocator<void> >::operator=(const sensor_msgs::Image_<std::allocator<void> >&)
/opt/ros/hydro/include/sensor_msgs/Image.h:56:8: note: no known conversion for argument 1 from ‘sensor_msgs::ImagePtr {aka boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > >}’ to ‘const sensor_msgs::Image_<std::allocator<void> >&’
make[2]: *** [custom_msg/CMakeFiles/publish.dir/publish.cpp.o] Error 1
make[1]: *** [custom_msg/CMakeFiles/publish.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed
I can understand that msg2.im = im_msg; isn't correct. Please help me fix this.
You are trying to assign a sensor_msgs::ImagePtr (a pointer) to a sensor_msgs::Image field. Simply you can't. Just look at the fifth line of your error log:
no known conversion for argument 1 from ‘sensor_msgs::ImagePtr {aka boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > >}’ to ‘const sensor_msgs::Image_<std::allocator<void> >&’
To solve this simple issue, just add the dereference operator (*) to that pointer:
msg2.im = *im_msg;
I assume that there are no other errors in the code.

Resources