Author Topic: Math.h "linker error" doesn't deal with variables or loops.  (Read 5271 times)

Offline e.dacougnia

  • Single posting newcomer
  • *
  • Posts: 5
Math.h "linker error" doesn't deal with variables or loops.
« on: August 29, 2021, 11:46:17 pm »
Good evening everyone,

-1 I have a problem with some of math.h functions like sin, cos or sqrt who are acting like if they could only handle "const double". Impossible to pass them thru a loop, it gives me a linker error.
   It doesn't want to build. Aren't they supposed to deal with variables in "C"?
   I work with Ubuntu 20.04 LTS

-2 Also, it is very very hard to get log on the forum and to go from one page to another. Each step cost me 50 try at least and dozens of minutes.
Thanks in advance!? :)

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Math.h "linker error" doesn't deal with variables or loops.
« Reply #1 on: August 30, 2021, 04:28:46 am »
If you are talking about the Wiki pages it is a known issue; I have no problem with the forums.

You should post the error because we have no psychic on this website to help you.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Math.h "linker error" doesn't deal with variables or loops.
« Reply #2 on: August 30, 2021, 10:59:32 am »
The installed version of Simple Mchines Forum does not work with IPv6 connections, see this thread

The linker error may be because you need to link explicitly the math library.

Offline e.dacougnia

  • Single posting newcomer
  • *
  • Posts: 5
Re: Math.h "linker error" doesn't deal with variables or loops.
« Reply #3 on: August 30, 2021, 01:07:17 pm »
Thank you for answering!

I haven't got to the wiki yet, just the forum.
I have shut IPv6, but might have to reconnect to see the difference, will tell you anyway. Thanks! :)

When you say "explicitly linked the math library" do you mean #include <math.h> or something else? Because that's done.
I didn't try every function in math.h, but I assume that some are working since the "round" function seems OK.
I'm able to find another way, but that won't be very efficient. If you have another hint for me, I'll take it?

Thanks to the both of you!
Have a nice day :)

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Math.h "linker error" doesn't deal with variables or loops.
« Reply #4 on: August 30, 2021, 02:03:07 pm »
Read this link. Some compilers (specially those for embedded systems) require explicit linking with the libm.a library if you use functions like cos().

Linking with libm.a requires going to Project -> Build options -> Linker settings -> Link libraries and add libm.a there. If this does not work, post the full build log in code tags.
« Last Edit: August 30, 2021, 05:52:23 pm by Miguel Gimenez »

Offline e.dacougnia

  • Single posting newcomer
  • *
  • Posts: 5
Re: Math.h "linker error" doesn't deal with variables or loops.
« Reply #5 on: August 30, 2021, 05:34:27 pm »
Thannnnnnnnnnk You! You really did help me!! :)

I understand that I have a lot of stuff to cover still, It's so complex.  :-\

My apology! I have just read the topic -> READ THIS BEFORE ASKING FOR HELP! too late.

Also like I said I've shut the IPv6 on the web link for the forum, but it didn't help.
I'll find a way! :)
You can destroy this topic after reading it or I will tomorrow!?
Thanks again!! :)

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Math.h "linker error" doesn't deal with variables or loops.
« Reply #6 on: August 30, 2021, 05:51:54 pm »
Do no delete the post, it may be useful for others some day.

Offline e.dacougnia

  • Single posting newcomer
  • *
  • Posts: 5
Re: Math.h "linker error" doesn't deal with variables or loops.
« Reply #7 on: August 31, 2021, 10:44:14 am »
So be it.
Thanks again!  :)