Build errors when compiling the 3pi simple-test

I am getting the following errors when trying to build the simple-test example from the 3pi users guide:

../main.c:12: undefined reference to `print'
../main.c:14: undefined reference to `play'
../main.c:21: undefined reference to `delay_ms'
../main.c:26: undefined reference to `delay_ms'

However, these functions look to be included in the header file; so, I can’t figure out why the compiler can’t find them.
Here is a copy of the code:

#include <pololu/3pi.h>

int main()
{
	print("Hello!");

	play("L16 ceg>c");

	while(1)
	{
		red_led(0);
		green_led(1);

		delay_ms(100);

		red_led(1);
		green_led(0);

		delay_ms(100);
	}

	return 0;
}

I’ve tried simply flashing to the 3pi anyway. When I do, no text appears on the screen, no sound, and the blue and green LED’s come on (not the red one). I would think that this would mean the program is getting stuck before the first delay_ms() function.

I think I may have made a mistake installing the pololu user libraries. I have multiple paths to 3pi.h. They are below:
/usr/local/CrossPack-AVR/avr/include/pololu/3pi.h
/usr/local/CrossPack-AVR/avr/libpololu-avr/pololu/3pi.h

I also have multiple paths to libpololu-atmega328p:
/usr/local/CrossPack-AVR/lib/libpololu-atmega328p
/usr/local/CrossPack-AVR/avr/libpololu-avr/libpololu-atmega328p

Any help is appreciated!

EDIT: I’m not sure if this information helps or not, but I thought I’d add it just in case. Operating from the command line with the given examples is not a problem. In other words, going here:
/usr/local/CrossPack-AVR/avr/libpololu-avr/examples/atmega328p/3pi-demo-program
Then, editing the make file to reflect the correct port and typing “make” builds successfully. Also, “make program” flashes to the 3pi correctly.
However, when working on new files in either Xcode or Eclipse, I get the errors mentioned above.

Hello.

An “undefined reference to” error usually means that you did not give the correct command-line option to tell the linker to use the Pololu AVR C/C++ Library; this error should prevent the linker from outputting a hex file. Please see the “Using the Pololu AVR Library for your own projects” section in the user’s guide for information about the arguments you need to use:
pololu.com/docs/0J20

If the provided Makefile works for you, then I recommend configuring Eclipse or XCode to simply run ‘make’; then you know that they will be invoking the compiler and linker correctly. I know this is possible with Eclipse but I don’t know about XCode.

–David

I’ve been messing around with this some more. So I’ve gone back and manually added in the atmega328p libraries and header files. This has eliminated the four errors where the compiler couldn’t see the functions mentioned previously. However, it has introduced two new errors. Here are screenshots of the eclipse IDE:
(AVRtest is a different project that happens to be in the same workspace.)


I’m not sure why these errors are here. I’m guessing the second error is there because of the first. I don’t know why the library in the given path isn’t found. It’s definitely there. Again, any help is appreciated.
I apologize if these are dumb questions. I’m pretty new to programming in general.

Please try using just -lpololu_atmega328p instead of specifying the whole path.

In general, if you have one procedure that works (typing make), and another procedure that doesn’t work (using Eclipse), then you should carefully compare the two to see how they are different. Eclipse shows you exactly what programs it is running in the Console view. Make shows you exactly programs it is running in your Terminal window when you type ‘make’.

If you have another error and can’t figure it out, please post the entire output from Eclipse’s Console view here.

–David

Below are screenshots of the terminal and the Eclipse console:
Terminal Screen


Eclipse Console


Eclipse wasn’t accessing the library correctly. I have fixed this. Thanks for the help, David!
I’ve noticed that elcipse seems to being doing a lot of other stuff as well, and i’m not exactly sure what all of it means. I know this is somewhat out of you all’s area of responsibility, but can you see anything in there that I might want to change?

I’m glad you got it working! I don’t see anything wrong with Eclipse’s output except the unneeded “.a” on the end of the “-l” argument, which I think you fixed.

–David

Is there an update to this for AVR Studio 5? I keep getting the same error message, “undefined reference to 'delay_ms” in file “time.h”.

Thanks.