Arduino 1.6.9/1.610 build fails with "'constexprint' does not name a type" - c++11

Supposedly Arduino's IDE > 1.6.2 has C++11 support.
I have just freshly downloaded and run version 1.6.9 on OSX (and as others have reported, this repros on Windows as well, with 1.6.9/1.6.10).
I cannot get this simple program to compile:
constexpr int get_five() { return 5; }
void setup() {
Serial.begin(9600);
Serial.println(get_five());
}
void loop() {
}
I receive this error when I try to build or upload:
sketch_jul25a:1: error: 'constexprint' does not name a type
constexpr int get_five() { return 5; }
^
exit status 1
'constexprint' does not name a type
I've looked at this question and answer, but it is supposedly no longer applicable in 1.6.9 version of the IDE that I am using - error: 'constexpr' does not name a type m- arduino ide
I have dug into the temporary files that are output by the IDE when building, and it seems it is trying to automatically generate headers for functions (I assume for multi-file sketch support), and does the wrong thing when it encounters constexpr:
#include <Arduino.h>
#line 1 "/Users/<my_username>/Documents/Arduino/sketch_jul25a/sketch_jul25a.ino"
#line 1 "/Users/<my_username>/Documents/Arduino/sketch_jul25a/sketch_jul25a.ino"
#line 1 "/Users/<my_username>/Documents/Arduino/sketch_jul25a/sketch_jul25a.ino"
constexprint get_five(); // **** <- This looks to be the culprit
#line 3 "/Users/<my_username>/Documents/Arduino/sketch_jul25a/sketch_jul25a.ino"
void setup();
#line 9 "/Users/<my_username>/Documents/Arduino/sketch_jul25a/sketch_jul25a.ino"
void loop();
#line 1 "/Users/<my_username>/Documents/Arduino/sketch_jul25a/sketch_jul25a.ino"
constexpr int get_five() { return 5; }
void setup() {
Serial.begin(9600);
Serial.println(get_five());
}
void loop() {
}
Is this a bug in the Arduino IDE? Is it unique to OSX? Is there a workaround that allows constexpr to work?
In googling I have found that some Arduino libraries are using constexpr, so I am assuming it could be made to work in some cases.

This is a known limitation of the arduino-builder.
Until it is fixed, you can add a prototype yourself above the function. This will prevent the IDE from incorrectly generating its own.
constexpr int get_five();
constexpr int get_five() { return 5; }
void setup() {
Serial.begin(9600);
Serial.println(get_five());
}
void loop() {
}

Related

C++ Internal compiler error working with native events

__event T e(args);
On line 9, VS gives me green squigglies under 'e' with the warning: Function definition for 'e' not found.
On compile/build, it throws the C1001 internal error occurred in the compiler (line 9 again).
I've tried renaming the variable, tried removing the template and just working with normal types, tried making it public.
If anyone can help it would be greatly appreciated, thank you.
(Whole code probably not necessary but just to give an idea what I'm going for)
#include <cstdarg>
#include <functional>
#include <iostream>
template <typename T, typename ... args>
[event_source(native)]
class Action {
private:
__event T e(args);
public:
~Action() {
__unhook(this);
};
void operator +=(std::function<T(args...)> f) {
__hook(e, this, &f);
}
void operator -=(std::function<T(args...)> f) {
__unhook(e, this, &f);
}
void operator()(args...) {
__raise e(args);
}
};
void print(const char* s) {
std::cout << s << std::endl;
}
int main() {
Action<void, const char*> printAction;
printAction += print;
printAction("Print a string.");
printAction -= print;
}

Porting pre-4.15 timer code for mali450 GPU kernel driver on ARM64

I have an old TV box based off the Amlogic S905X ARM64 SoC, a Tanix TX5, which originally ran Android on it. I don't like being locked out of the potential of my hardware, so I followed closely the progress of the Armbian project, and I recently have installed version 5.67, which is based off Ubuntu Bionic, running on Linux 4.19.6.
Everything works great, there are working drivers for ethernet, wifi, blutooth, etc, but there is unfortunately no kernel driver included to support the integrated mali450 gpu. The hdmi output does work, but Xorg is running on fbdev, and screen updating is painfully slow, videos are unwatchable in full screen. I'm not too sure what the story is but apparently amlogic keeps their current version of the driver to themselves. However by going on their FTP site, I found an old source tree for the kernel driver ( http://openlinux.amlogic.com:8000/download/ARM/gpu/gpu-2016-08-18-fe6d7b1d1b.tar.gz ). It is out of date, but I have made some headway into porting it to the current kernel, with mostly easy fixes up to now. I can now compile about half of the source files just fine.
I should clarify I'm not a linux developer by trade, I'm not even a C developer... I dabble, I know just enough to be dangerous, and I'm highly motivated. My daily trade is C# though, so I do know more or less what I'm doing.
The current issue I am having is with mali/linux/mali_osk_timers.c . This is the original code:
/*
* Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved.
*
* This program is free software and is provided to you under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
*
* A copy of the licence is included with the program, and can also be obtained from Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/**
* #file mali_osk_timers.c
* Implementation of the OS abstraction layer for the kernel device driver
*/
#include <linux/timer.h>
#include <linux/slab.h>
#include "mali_osk.h"
#include "mali_kernel_common.h"
struct _mali_osk_timer_t_struct {
struct timer_list timer;
};
typedef void (*timer_timeout_function_t)(unsigned long);
_mali_osk_timer_t *_mali_osk_timer_init(void)
{
_mali_osk_timer_t *t = (_mali_osk_timer_t *)kmalloc(sizeof(_mali_osk_timer_t), GFP_KERNEL);
if (NULL != t) init_timer(&t->timer);
return t;
}
void _mali_osk_timer_add(_mali_osk_timer_t *tim, unsigned long ticks_to_expire)
{
MALI_DEBUG_ASSERT_POINTER(tim);
tim->timer.expires = jiffies + ticks_to_expire;
add_timer(&(tim->timer));
}
void _mali_osk_timer_mod(_mali_osk_timer_t *tim, unsigned long ticks_to_expire)
{
MALI_DEBUG_ASSERT_POINTER(tim);
mod_timer(&(tim->timer), jiffies + ticks_to_expire);
}
void _mali_osk_timer_del(_mali_osk_timer_t *tim)
{
MALI_DEBUG_ASSERT_POINTER(tim);
del_timer_sync(&(tim->timer));
}
void _mali_osk_timer_del_async(_mali_osk_timer_t *tim)
{
MALI_DEBUG_ASSERT_POINTER(tim);
del_timer(&(tim->timer));
}
mali_bool _mali_osk_timer_pending(_mali_osk_timer_t *tim)
{
MALI_DEBUG_ASSERT_POINTER(tim);
return 1 == timer_pending(&(tim->timer));
}
void _mali_osk_timer_setcallback(_mali_osk_timer_t *tim, _mali_osk_timer_callback_t callback, void *data)
{
MALI_DEBUG_ASSERT_POINTER(tim);
tim->timer.data = (unsigned long)data;
tim->timer.function = (timer_timeout_function_t)callback;
}
void _mali_osk_timer_term(_mali_osk_timer_t *tim)
{
MALI_DEBUG_ASSERT_POINTER(tim);
kfree(tim);
}
The main problem here is that this code uses the timers via an interface that was deprecated long ago, and removed entirely from the kernel in 4.15. I was able to look up how to port this code, and managed almost the entire file, but in the end I'm not familiar enough with C syntax and pointer usage rules to figure out how to do it. The main problematic is the _mali_osk_timer_setcallback() function. I'm not really sure how to go about modifying it while also keeping the same function signature.
Edit
Here is the current code, and the current output from the compiler:
/*
* Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved.
*
* This program is free software and is provided to you under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
*
* A copy of the licence is included with the program, and can also be obtained from Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/**
* #file mali_osk_timers.c
* Implementation of the OS abstraction layer for the kernel device driver
*/
#include <linux/timer.h>
#include <linux/slab.h>
#include "mali_osk.h"
#include "mali_kernel_common.h"
#define MALI_TIMER_FLAGS 0
struct _mali_osk_timer_t_struct {
struct timer_list timer;
void (*ticked)(unsigned long data);
};
static void tick_trampoline(struct timer_list *t) {
typedef struct _mali_osk_timer_t_struct Tldr;
Tldr *m = container_of(t, Tldr, timer);
m->ticked(t->data);
}
typedef void (*timer_timeout_function_t)(unsigned long);
_mali_osk_timer_t *_mali_osk_timer_init(void)
{
_mali_osk_timer_t *t = (_mali_osk_timer_t *)kmalloc(sizeof(_mali_osk_timer_t), GFP_KERNEL);
if (NULL != t) timer_setup(&(t->timer), tick_trampoline, MALI_TIMER_FLAGS);
return t;
}
void _mali_osk_timer_add(_mali_osk_timer_t *tim, unsigned long ticks_to_expire)
{
MALI_DEBUG_ASSERT_POINTER(tim);
tim->timer.expires = jiffies + ticks_to_expire;
add_timer(&(tim->timer));
}
void _mali_osk_timer_mod(_mali_osk_timer_t *tim, unsigned long ticks_to_expire)
{
MALI_DEBUG_ASSERT_POINTER(tim);
mod_timer(&(tim->timer), jiffies + ticks_to_expire);
}
void _mali_osk_timer_del(_mali_osk_timer_t *tim)
{
MALI_DEBUG_ASSERT_POINTER(tim);
del_timer_sync(&(tim->timer));
}
void _mali_osk_timer_del_async(_mali_osk_timer_t *tim)
{
MALI_DEBUG_ASSERT_POINTER(tim);
del_timer(&(tim->timer));
}
mali_bool _mali_osk_timer_pending(_mali_osk_timer_t *tim)
{
MALI_DEBUG_ASSERT_POINTER(tim);
return 1 == timer_pending(&(tim->timer));
}
void _mali_osk_timer_setcallback(_mali_osk_timer_t *tim, _mali_osk_timer_callback_t callback, void *data)
{
MALI_DEBUG_ASSERT_POINTER(tim);
&(tim->timer).data = (unsigned long)data;
tim->ticked = (timer_timeout_function_t)callback; /* Note no cast */
timer_setup(&(tim->timer), tick_trampoline, MALI_TIMER_FLAGS);
}
void _mali_osk_timer_term(_mali_osk_timer_t *tim)
{
MALI_DEBUG_ASSERT_POINTER(tim);
kfree(tim);
}
_
hugo#tx5:/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali$ sudo KDIR=../../kernel/Amlogic_s905-kernel USING_UMP=0 BUILD=release make
make ARCH=arm64 -C ../../kernel/Amlogic_s905-kernel M=/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali modules
make[1]: Entering directory '/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/kernel/Amlogic_s905-kernel'
WARNING: Symbol version dump ./Module.symvers
is missing; modules will have no dependencies and modversions.
CC [M] /media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali/linux/mali_osk_timers.o
/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali/linux/mali_osk_timers.c: In function ‘tick_trampoline’:
/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali/linux/mali_osk_timers.c:31:17: error: ‘struct timer_list’ has no member named ‘data’
m->ticked(t->data);
^~
/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali/linux/mali_osk_timers.c: In function ‘_mali_osk_timer_setcallback’:
/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali/linux/mali_osk_timers.c:77:18: error: ‘struct timer_list’ has no member named ‘data’
&(tim->timer).data = (unsigned long)data;
^
/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali/linux/mali_osk_timers.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-data-time’
scripts/Makefile.build:305: recipe for target '/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali/linux/mali_osk_timers.o' failed
make[2]: *** [/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali/linux/mali_osk_timers.o] Error 1
Makefile:1517: recipe for target '_module_/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali' failed
make[1]: *** [_module_/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/gpu-2016-08-18-fe6d7b1d1b/mali] Error 2
make[1]: Leaving directory '/media/hugo/7d79c22a-4ac8-4fcb-ae1c-3310a851a73d/kernel/Amlogic_s905-kernel'
Makefile:192: recipe for target 'all' failed
make: *** [all] Error 2
The new timer interface, gasp, leaves the context value inside the timer structure, and passes a pointer to that structure instead. The idea is that
use of data will go away, as the common idiom was that data was a pointer to
a structure that contained the timer_list structure.
Since you probably want to minimize the changes to mali, the changes outlined here should help; it just inserts a little protocol conversion function to make it look like the old way.
struct _mali_osk_timer_t_struct {
struct timer_list timer;
unsigned long data;
void (*ticked)(unsigned long data); /* Add this */
};
#define MALI_TIMER_FLAGS 0 /* NB: choose the right bits for this! */
/* This function converts between the “new” and “old” notifications */
static void tick_trampoline(struct timer *t) {
typedef struct _mali_osk_timer_t_struct Tldr;
Tldr *m = container_of(t, Tldr, timer);
m->ticked(m->data);
}
/* change this one: */
void _mali_osk_timer_setcallback(_mali_osk_timer_t *tim, _mali_osk_timer_callback_t callback, void *data)
{
MALI_DEBUG_ASSERT_POINTER(tim);
tim->data = (unsigned long)data;
tim->ticked = callback; /* Note no cast */
timer_setup(&tim->ticked, tick_trampoline, MALI_TIMER_FLAGS);
}
The “No cast” is a plea to let the type system do its job.

Boost thread v1.53 segmentation fault

The following program produces a segmentation fault, although I don't see any undefined behaviour in the code. It has been compiled with GCC 4.7.3. Do you know the reason of the fault or a possible work-around? Also, it seems boost::future does not exist in v1.53 yet, so I should probably rely on boost::unique_future. I cannot upgrade to any version above > 1.53 and I really need the "make_ready_at_thread_exit()" feature.
#define BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK
#include <boost/thread.hpp>
#include <boost/thread/future.hpp>
namespace th = boost;
struct S {
th::packaged_task<void()> task;
th::unique_future<void> future;
void start();
void stop();
};
void S::start() {
task = th::packaged_task<void()>{ [this] () {}};
future = task.get_future();
task.make_ready_at_thread_exit();
}
void S::stop() {
future.wait();
}
int main() {
S s;
s.start();
s.stop();
}

.dll error on boost compiled app

simple app, just learning to setup my boost environment...
program compiles, but I get a libboost_thread-mgw44-mt-1_51.dll is missing error
on a sidenote, I had to change thread1.stop() to t1.stop() as boost said there was no function for stop().
I have the dll, placing the dll in the same folder as the app doesn't do anything.
#include <boost/bind.hpp>
#include <boost/thread.hpp>
class Threadable
{
public:
void stop()
{
running = false;
}
int run()
{
running = true;
while(running)
{
//Do Something Meaningful
}
return 0;
}
private:
bool running;
};
int main()
{
Threadable t1, t2;
boost::thread thread1(boost::bind(&Threadable::run, t1));
boost::thread thread2(boost::bind(&Threadable::run, t2));
// Let the threads run for half a second
boost::this_thread::sleep(boost::posix_time::milliseconds(500));
// Signal them to stop
t1.stop();
t2.stop();
//thread1.stop();
//thread2.stop();
// Wait for them to gracefully exit
thread1.join();
thread2.join();
return 0;
}

Visual Studio 2010: strange linker error

I have the following code in my project:
SomeCode.h :
#pragma once
#include "defines.h"
void Function1(int *param1, float *param2, int count);
void Function2(int *param1, float *param2);
void Function3(int *param1, float *param2);
SomeCode.cpp :
#include "SomeCode.h"
void Function1(int *param1, float *param2, int count)
{
//implementation
}
void Function2(int *param1, float *param2)
{
//implementation
}
void Function3(int *param1, float *param2)
{
//implementation
}
main.cpp:
#include "SomeCode.h"
int main()
{
// some Function1, Function2, Function3 usage
}
All the above files are in the same folder.
The solution compiles fine, but i get Function1, Function2, Function3 unresolved external errors. Cleaning and building again doesn't help. However a magical workaround to make it building successfully is the following:
1) comment all the lines in SomeCode.cpp
2) build the solution and get the same linker errors
3) uncomment the lines
4) build again
I encounter the same problem from time to time when I change something in my project (adding new files, making changes to existing once). However this happens not on a regular basis, so I can't tell precisely when the problem appear.
Any ideas what might cause these troubles?
Do you try to add a
#include "somecode.h
In somecode.cpp ?

Resources