- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Especially thanks to motoo tanaka for testing out my basic test program. I simplified the test program even more, but still get compiler failure. This time I just took exactly what you wrote, but left out the printing part. The following is a copy, including the error messages. This should work. I just don't understand.
#include "project.h"
#include "math.h"
double A=1.0;
double B=1.0;
uint8_t n ;
int main(void)
{
for(;;)
{
for (n = 1 ; n <= 10 ; n++)
{
B = exp(5.0 / n) ;
if (n == 10)
{
A = 1.0 ;
B = 1.0 ;
}
}
} *****this is the line number 22 that the error message refers to
}
/* [] END OF FILE */
ERROR MESSAGE ARE AS FOLLOWS
OK. So the messages I get are as follows:
"collect2.exe: error: ld returned 1 exit status"
It also said " The command 'arm-none-eabi-gcc.exe' failed with exit code '1'. "
It also said this in the notice list
"build error: undefined reference to 'exp' line 22" (I marked line 22 so you could see what they were referring to. Don't know how to copy the listing with line numbers included)
So how come this fails to compile ? Such a simple program. As before, using psoc5lp board and creator version 3.3
Solved! Go to Solution.
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Please add "m" in the
Project > Build Settings > Linker > General > Additional Libraries
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
RoBu,
I placed your posted code in PSoC Creator 4.3.
No special link settings.
I compiled it. No Error.
Hmmm?
Since it was complaining about exp(), it appears your build could not find math.h where exp() is declared.
build error: undefined reference to 'exp'
Maybe there is an issue with PSoC Creator 3.3. You might consider upgrading.
Len
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Shouldn't the include be:
#include <math.h>
rather than:
#include "math.h"
The double quotes will only search the current project working directory.
math.h is a standard library, so you have to include it with angle brackets rather than double quotes.
Same goes for other libraries like stdlib.h, string.h, etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
> The double quotes will only search the current project working directory.
> math.h is a standard library, so you have to include it with angle brackets rather than double quotes.
In the world of standard C and/or posix your statement is correct.
But PSoC Creator kindly (?) takes care of double quotes for its standard include directories,
which include usual standard c library headers.
To be honest, I was confused by this, too.
> I placed your posted code in PSoC Creator 4.3.
> No special link settings.
Did you use "my" posted code?
If so, I have already included "m" in the linker settings.
If I remember correct, even standard c requires "-lm" for math library
as math library is relatively heavy.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
moto,
I created a "new" project and pasted RoBu's posted code for main() in main.c. No special linker settings. It compiled with no issues.
Maybe this is an improvement in latest version of PSoC Creator.
Len
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Len-san,
Coincidentally I installed PSoC Creator v4.3 today.
So I tried the following
(1) I created a blank project "math_test_200305_wo_m" for CY8C5888LTI-LP097 and copied the following main.c
main.c
=================
#include "project.h"
#include "math.h"
double A = 1.0 ;
double B = 1.0 ;
uint8_t n ;
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
for(;;) {
for (n = 1 ; n <= 10 ; n++) {
B = exp(5.0 / n) ;
if (n == 10) {
A = 1.0 ;
B = 1.0 ;
}
}
}
}
=================
(2) Clean and Build the project without touching any configuration/linker parameter.
prj.M0120:Build error: undefined reference to 'exp'
(3) Then I copied the project to "math_test_200305_w_m"
and added "m" in the Linker > General > Additional Libraries
(4) Clean and Build
Build Succeeded: 03/05/2020 21:14:32
So I think that it's not the version of PSoC Creator.
But I suppose that your environment setting(s) may have something
which automatically add "m" or "-lm" in the compiler option.
Best Regards,
5-Mar-2020
Motoo Tanaka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
moto,
You are correct. My mistake is that I performed a "compile"-only on main.c. No errors reported. When I performed a full build, I received the "exp" undefined error as you did during the linker phase. When I added the "m" library, the linker problem went away.
Thanks for your support on the forums.
Len
"Engineering is an Art. The Art of Compromise."