Shop OBEX P1 Docs P2 Docs Learn Events
Compile error: undefined reference to ... — Parallax Forums

Compile error: undefined reference to ...

Michel LMichel L Posts: 141
edited 2014-05-18 01:05 in Propeller 1
I'm currently working on a graphical development environment: BlocklyProp. On request I'm implementing c but when I'm compiling I get some errors. And as this are my first steps in prop-gcc I have no idea where to start to look for them.

The code works perfectly when I build it using SimpleIDE but get some errors when using my own IDE.

The code:
#include "simpletools.h"


int main() {
  while(1) {
    high(16);
    pause(1000);
    low(16);
    pause(1000);
  }

}

The command line command (split over multiple lines for readability). This call work when I leave the main() empty and just have the include.
propeller-elf-gcc
-I D:\Data\Mijn documenten\NetBeansProjects\BlocklyProp\propeller-c-lib\Utility\libsimpletools
-L D:\Data\Mijn documenten\NetBeansProjects\BlocklyProp\propeller-c-lib\Utility\libsimpletools\cmm
-I D:\Data\Mijn documenten\NetBeansProjects\BlocklyProp\propeller-c-lib\Text Devices\libsimpletext
-L D:\Data\Mijn documenten\NetBeansProjects\BlocklyProp\propeller-c-lib\Text Devices\libsimpletext\cmm
-I D:\Data\Mijn documenten\NetBeansProjects\BlocklyProp\propeller-c-lib\Protocol\libsimplei2c
-L D:\Data\Mijn documenten\NetBeansProjects\BlocklyProp\propeller-c-lib\Protocol\libsimplei2c\cmm 
-Os 
-mcmm 
-m32bit-doubles
-std=c99
-lm
-lsimpletools
-lsimpletext 
-lsimplei2c 
-o C:\Users\Michel\AppData\Local\Temp\blocklyapp4130086703445820848.elf
C:\Users\Michel\AppData\Local\Temp\blocklyapp5856706119161387990.c

The compiler output:
C:\Users\Michel\AppData\Local\Temp\cc2QF5o2.o: In function `_main':
(.text+0x5): undefined reference to `_high'
C:\Users\Michel\AppData\Local\Temp\cc2QF5o2.o: In function `_main':
(.text+0xb): undefined reference to `_pause'
C:\Users\Michel\AppData\Local\Temp\cc2QF5o2.o: In function `_main':
(.text+0x10): undefined reference to `_low'
C:\Users\Michel\AppData\Local\Temp\cc2QF5o2.o: In function `_main':
(.text+0x16): undefined reference to `_pause'
collect2: ld returned 1 exit status

Any ideas?

I've also been looking for documentation of the propeller-elf-gcc arguments. But so far I've found nothing. All arguments I using now are copied from the SimpleIDE output.

Thanks in advance,

Michel

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-05-17 08:16
    Well. it seems your other IDE doesn't find simpletools.h
    It is way over my head to say why that is so.
  • Michel LMichel L Posts: 141
    edited 2014-05-17 08:30
    Well. it seems your other IDE doesn't find simpletools.h
    It is way over my head to say why that is so.

    That's what I first thought. But if I leave the main function empty but keep include it works. If I leave out the command line argument pointing to the lib directories then I get "not found" exceptions.

    Because of that I don't think that's the problem.
  • Michel LMichel L Posts: 141
    edited 2014-05-17 10:54
    Fixed it by trial and error.

    For some reason:
    -lm -lsimpletools -lsimpletext -lsimplei2c
    
    have to stand behind the input and output file.

    I have no idea why, and because I usualy set the source and destination file at the end of the command I had this problem.

    Although it is fixed, an explanation would be nice. I'm one of those that is not happy when it just works, I like to know why.

    @Loopy Byteloose
    I forgot to thank you for your input in my previous message, sorry.
  • jazzedjazzed Posts: 11,803
    edited 2014-05-17 11:17
    Michel L wrote: »
    Fixed it by trial and error.

    For some reason:
    -lm -lsimpletools -lsimpletext -lsimplei2c
    
    have to stand behind the input and output file.

    I have no idea why, and because I usualy set the source and destination file at the end of the command I had this problem.

    Although it is fixed, an explanation would be nice. I'm one of those that is not happy when it just works, I like to know why.


    This is the way gcc works for any processor. It is not obvious ... SimpleIDE does this work for you.

    GCC general options are documented here: https://gcc.gnu.org/onlinedocs/gcc/

    Propeller specific options are documented in the propgcc.googlecode.com site wiki pages and here: https://propgcc.googlecode.com/files/gcc.pdf

  • Michel LMichel L Posts: 141
    edited 2014-05-17 11:27
    jazzed,

    thanks, it's not easy taking your first steps in C while writing an IDE for it.

    I'll have a look at these references when I have to make changes. I've managed to create my first program, compile it and load the .elf file into my prop.
    That was the first time I actually ran a c-program in my prop. Until now it has always been spin.

    Michel
  • jazzedjazzed Posts: 11,803
    edited 2014-05-17 11:32
    Congrats Michel.

    My computer was turned off and packed in a box at the time of your post.

    If you open the build status pane in SimpleIDE, you will see all the steps of the tools when building and loading a program.
  • Heater.Heater. Posts: 21,230
    edited 2014-05-18 01:05
    Michel L,

    I always imagine it working like this.

    If you put the "-lwhateverlibrary" first then the GCC linker, looks at that archive, decides it does not need it for anything because it has no external names to resolve and then throws it away.
    Then the linker pulls in the object module compiled from your code and sees those unresolved symbols.
    Oops it's forgotten you specified the library at that point.

    If you put the libraries at the end of the list then when the linker gets to them it sees that they resolve the unresolved symbols it has found in your program and makes use of them.

    This all sounds a bit silly but it does mean that you can include functions in your program that have the same names as functions in a library. In which case the version you have written in your program will be used first and the library version ignored. You can override library functions, sometimes very useful.

    This has caught me out many times over the years as well.
Sign In or Register to comment.