colin wrote:noether wrote:colin wrote:Actually I found that the right way to solve the problem is to disable C++ exception support in gcc:
Code: Select all
USE_CPPOPT = -fno-rtti -fno-exceptions
The g++ exception handling support uses abort() and friends to handle uncaught exceptions.
My problem arises when I link to the Eigen C++ library, if I do not use this library, everything compiles fine, no matter what -Ox level I employ.
Are you building Eigen from source? I think the same -f(no-)exceptions flag setting must be used for all linked code in a program. Can Eigen be compiled without exception support, or is it required?
Hello colin,
Eigen is a C++ template library for linear algebra, is all headers .hh. So it is not compiled before.
I have attached the project. Take a look to the Makefile and swap -O2 by -O0 and the linker error triggers. As you wrote earlier, the same error triggers if you do not put the -fno-exceptions flag.
Fill the DINCDIR variable with the Eigen directory, if you are using Linux, Eigen should be included in your official repository, in my machine is ' /usr/include/eigen3/ ' .
I have spent all the afternoon, and preprocessing (gcc -E) the main.cpp with -O0, there is any call to abort... I do not know where is magically invoked u_U.
If you remove Eigen from the main.cpp, the project compiles fine.
EDIT:
it seems there is a problem uploading the project and the post appears empty after attaching it.
The project is very simple, just take the c++ example, and put this main.cpp
Code: Select all
#include "ch.h"
#include "hal.h"
#include "Eigen/Dense"
using namespace Eigen;
static WORKING_AREA(waThread1, 128);
static msg_t Thread1(void *arg) {
(void)arg;
chRegSetThreadName("blinker");
int i = 1;
Matrix<float, 13, 13> A, L;
A = Matrix<float, 13, 13>::Identity(13, 13) +
Matrix<float, 13, 13>::Constant(1);
while (TRUE)
{
i++;
L = A.llt().matrixL();
A(0, 0) += i;
palSetPad(GPIOD, GPIOD_LED3); /* Orange. */
chThdSleepMilliseconds(500);
palClearPad(GPIOD, GPIOD_LED3); /* Orange. */
chThdSleepMilliseconds(500);
}
}
int main(void) {
halInit();
chSysInit();
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
while (TRUE) {
chThdSleepMilliseconds(500);
}
}
The Makefile for flags is:
Code: Select all
# Compiler options here.
ifeq ($(USE_OPT),)
USE_OPT = -O0 -ggdb -fomit-frame-pointer -falign-functions=16 -mhard-float -mfpu=fpv4-sp-d16 -fsingle-precision-constant -DNDEBUG -fno-exceptions
endif
# C specific options here (added to USE_OPT).
ifeq ($(USE_COPT),)
USE_COPT =
endif
# C++ specific options here (added to USE_OPT).
ifeq ($(USE_CPPOPT),)
USE_CPPOPT = -fno-rtti
endif
DINCDIR = /usr/include/eigen3/ <- put where Eigen is installed