Thanks for all the suggestions regarding array manipulations. Still having compiler problems, however

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
RoBu_286116
Level 1
Level 1

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

0 Likes
1 Solution
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Please add "m" in the

Project > Build Settings > Linker > General > Additional Libraries

010-Build-Settings-m.JPG

moto

View solution in original post

0 Likes
7 Replies
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Please add "m" in the

Project > Build Settings > Linker > General > Additional Libraries

010-Build-Settings-m.JPG

moto

0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

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

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
KyTr_1955226
Level 6
Level 6
250 sign-ins 10 likes given 50 solutions authored

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.

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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

0 Likes

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

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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'

020-wo_m_failed.JPG

(3) Then I copied the project to "math_test_200305_w_m"

and added "m" in the Linker > General > Additional Libraries

021-w-m.JPG

(4) Clean and Build

Build Succeeded: 03/05/2020 21:14:32

022-w-compiled.JPG

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

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

Len
"Engineering is an Art. The Art of Compromise."