Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 11 months ago.
gcc4mbed gets errors on m3pi library
I used Adam Green's gcc4mbed as an offline tool. I was easily able to do some simple programs with the mbed. My goal is to use the mbed on the m3pi robot. When I tried to compile with the m3pi library, I got these errors:
arm-none-eabi-g++ -mcpu=cortex-m3 -mthumb -c -Os -fno-common -fmessage-length=0 -Wall -fno-exceptions -ffunction-section s -fdata-sections -DTARGET_LPC1768 -DTARGET_M3 -DTARGET_NXP -DTARGET_LPC176X -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -DCO RTEX_M3 -DARM_MATH_CM3 -std=gnu++98 -I. -I./m3pi -I./mbed -I./mbed/LPC1768 -I./mbed/LPC1768/GCC_ARM -I./HMC6352 -o m3p i/m3pi.o m3pi/m3pi.cpp m3pi/m3pi.cpp: In member function 'void m3pi::motor(int, float)': m3pi/m3pi.cpp:91:41: error: call of overloaded 'abs(float&)' is ambiguous m3pi/m3pi.cpp:91:41: note: candidates are:
It looks like the problem is located here in the m3pi library:
void m3pi::motor (int motor, float speed) { char opcode = 0x0; if (speed > 0.0) { if (motor==1) opcode = M1_FORWARD; else opcode = M2_FORWARD; } else { if (motor==1) opcode = M1_BACKWARD; else opcode = M2_BACKWARD; } unsigned char arg = 0x7f * abs(speed); _ser.putc(opcode); _ser.putc(arg); }
More specifically, it is in the call "abs(speed)"
I don't get any errors when I use the online compiler. Any ideas on what is happening differently with gcc4mbed?
Thank you, Keith
1 Answer
10 years, 11 months ago.
Based on what it looks like this code wants to do, the code should probably be calling fabs() instead of abs() since it appears that it wants to scale the 0x7f (127) value by the speed magnitude.
Thanks Adam! I would like to ask a favor though. Could you help me understand what is going on here?
This compiles with online compiler using abs. From what I have read, this should work with C++ as it is overloaded for all the numerical data types. The gcc arm compiler needs it to be fabs. From what I read, C requires the use of fabs since there is no overloading. What I am trying to understand is the difference in the way the two compilers are behaving.
Again, a BIG THANKS, Keith
PS Also, thanks for your work on gcc4mbed. Works great!
posted by 11 Sep 2013