Author Topic: Linker error - Can't use stdlib.h or math.h functions!  (Read 4417 times)

0 Members and 1 Guest are viewing this topic.

Offline blue_bear_94

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 801
  • Rating: +25/-35
  • Touhou Enthusiast / Former Troll / 68k Programmer
    • View Profile
Linker error - Can't use stdlib.h or math.h functions!
« on: March 04, 2013, 05:37:33 pm »
When I try to use stdlib.h functions (regardless of whether I #include <stdlib.h> or not), I get linker errors like these:
Code: [Select]
bullets.o: In function '_freeList':
bullets.c:(.text+0x384): undefined reference to '_free'
bullets.o: In function '_createNode':
bullets.c:(.text+0x39c): undefined reference to '_malloc'

Same for math.h functions. I also have the fxcglib installed. Are these functions not implemented yet?

Thanks in advance!
Due to dissatisfaction, I will be inactive on Omnimaga until further notice. (?? THP hasn't been much success and there's also the CE. I might possibly be here for a while.)
If you want to implore me to come back, or otherwise contact me, I can be found on GitHub (bluebear94), Twitter (@melranosF_), Reddit (/u/Fluffy8x), or e-mail (if you know my address). As a last resort, send me a PM on Cemetech (bluebear94) or join Touhou Prono (don't be fooled by the name). I've also enabled notifications for PMs on Omnimaga, but I don't advise using that since I might be banned.
Elvyna (Sunrise) 4 5%
TI-84+SE User (2.30 2.55 MP 2.43)
TI-89 Titanium User (3.10)
Casio Prizm User? (1.02)
Bag  東方ぷろの

Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: Linker error - Can't use stdlib.h or math.h functions!
« Reply #1 on: March 04, 2013, 11:46:44 pm »
How did you compiled your program? What's the gcc command line used to compile this?
« Last Edit: March 04, 2013, 11:47:53 pm by Juju »

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Linker error - Can't use stdlib.h or math.h functions!
« Reply #2 on: March 05, 2013, 12:38:49 am »
Both malloc and free are implemented in <stdlib.h>, but try including the raw library in your build folder and using
Code: [Select]
#include "stdlib.h" to see if that fixes the problem. Otherwise, you're not calling the linker properly.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline blue_bear_94

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 801
  • Rating: +25/-35
  • Touhou Enthusiast / Former Troll / 68k Programmer
    • View Profile
Re: Linker error - Can't use stdlib.h or math.h functions!
« Reply #3 on: March 05, 2013, 03:51:25 pm »
How did you compiled your program? What's the gcc command line used to compile this?
Code: [Select]
> sh3eb-elf-gcc bullets.o posnmath.o starvak2.o xpo.o -mb -m4a-nofpu -mhitachi -nostdlib -TC:/Users/Kook/Desktop/TISTUFF/PrizmSDK-0.3/common/prizm.ld -Wl,-static -Wl,-gc-sections -LC:/Users/Kook/Desktop/TISTUFF/PrizmSDK-0.3/lib -lfxcg -lgcc -o C:/Users/Kook/Desktop/TISTUFF/PrizmSDK-0.3/projects/starvak2/starvak2.bin For some reason it's ignoring the standard libs. However, I can't change this because the make.bat file calls make.exe in the /bin folder.
Both malloc and free are implemented in <stdlib.h>, but try including the raw library in your build folder and using
Code: [Select]
#include "stdlib.h" to see if that fixes the problem. Otherwise, you're not calling the linker properly.
Will try!


Edit: tried it, and got the same error.
« Last Edit: March 05, 2013, 03:55:45 pm by blue_bear_94 »
Due to dissatisfaction, I will be inactive on Omnimaga until further notice. (?? THP hasn't been much success and there's also the CE. I might possibly be here for a while.)
If you want to implore me to come back, or otherwise contact me, I can be found on GitHub (bluebear94), Twitter (@melranosF_), Reddit (/u/Fluffy8x), or e-mail (if you know my address). As a last resort, send me a PM on Cemetech (bluebear94) or join Touhou Prono (don't be fooled by the name). I've also enabled notifications for PMs on Omnimaga, but I don't advise using that since I might be banned.
Elvyna (Sunrise) 4 5%
TI-84+SE User (2.30 2.55 MP 2.43)
TI-89 Titanium User (3.10)
Casio Prizm User? (1.02)
Bag  東方ぷろの

Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: Linker error - Can't use stdlib.h or math.h functions!
« Reply #4 on: March 05, 2013, 04:25:35 pm »
Try -lc in the command line?

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline blue_bear_94

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 801
  • Rating: +25/-35
  • Touhou Enthusiast / Former Troll / 68k Programmer
    • View Profile
Re: Linker error - Can't use stdlib.h or math.h functions!
« Reply #5 on: March 05, 2013, 04:43:34 pm »
Well, I use the make.bat file, which calls make.exe, so using -lc here doesn't work.
Due to dissatisfaction, I will be inactive on Omnimaga until further notice. (?? THP hasn't been much success and there's also the CE. I might possibly be here for a while.)
If you want to implore me to come back, or otherwise contact me, I can be found on GitHub (bluebear94), Twitter (@melranosF_), Reddit (/u/Fluffy8x), or e-mail (if you know my address). As a last resort, send me a PM on Cemetech (bluebear94) or join Touhou Prono (don't be fooled by the name). I've also enabled notifications for PMs on Omnimaga, but I don't advise using that since I might be banned.
Elvyna (Sunrise) 4 5%
TI-84+SE User (2.30 2.55 MP 2.43)
TI-89 Titanium User (3.10)
Casio Prizm User? (1.02)
Bag  東方ぷろの

Offline blue_bear_94

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 801
  • Rating: +25/-35
  • Touhou Enthusiast / Former Troll / 68k Programmer
    • View Profile
Re: Linker error - Can't use stdlib.h or math.h functions!
« Reply #6 on: March 07, 2013, 05:30:48 pm »
Deleting the -nostdlib flag in /common/prizm_rules and calling make.bat again resulted in these errors:
Code: [Select]
...: In function 'stack_k':
(.text+0x50): undefined reference to '_stack'
...
_end_k; end
_main_k; __setup_argv_and_call_main
_atexit_k; _atexit
And it goes on and on.
Due to dissatisfaction, I will be inactive on Omnimaga until further notice. (?? THP hasn't been much success and there's also the CE. I might possibly be here for a while.)
If you want to implore me to come back, or otherwise contact me, I can be found on GitHub (bluebear94), Twitter (@melranosF_), Reddit (/u/Fluffy8x), or e-mail (if you know my address). As a last resort, send me a PM on Cemetech (bluebear94) or join Touhou Prono (don't be fooled by the name). I've also enabled notifications for PMs on Omnimaga, but I don't advise using that since I might be banned.
Elvyna (Sunrise) 4 5%
TI-84+SE User (2.30 2.55 MP 2.43)
TI-89 Titanium User (3.10)
Casio Prizm User? (1.02)
Bag  東方ぷろの