0

I am starting the breaking out portion of pset3. I am encountering numerous issues with spl. First and foremost, I made a test code to see the size of the paddle. My code is as follows

// standard libraries
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// Stanford Portable Library
#include <spl/gevents.h>
#include <spl/gobjects.h>
#include <spl/gwindow.h>

int main (int argc, string argv[])
{
    GWindow apple = newGWindow(240, 360);
    GRect test = newGRect(0, 0, 20, 5);
    add(apple, test);
    return 0;
}

however when I compile I get the error

jharvard@appliance (~/Dropbox/pset3/breakout): make testing
clang -ggdb3 -O0 -std=c99 -Wall -Werror    testing.c  -lcs50 -lm -o testing
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info):                relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info):   relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info):  relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info):                                  relocation 19 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 20 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 21 has invalid symbol index 22
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/bin/../lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
/tmp/testing-9ff130.o: In function `main_':
/home/jharvard/Dropbox/pset3/breakout/testing.c:14: undefined reference to `newGWindow'
/home/jharvard/Dropbox/pset3/breakout/testing.c:15: undefined reference to `newGRect'
/home/jharvard/Dropbox/pset3/breakout/testing.c:16: undefined reference to `add'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [testing] Error 1

I have absolutely no idea why.

Furthermore, I tried to ignore this and proceed to initPaddle. When I put the following code it works correctly.

GRect initPaddle(GWindow window)
{
    GRect paddle = newGRect(200, 450, 40, 10);
    setColor(paddle, "BLACK");
    setFillColor(paddle, "BLACK");
    setFilled(paddle, true);
    add(window, paddle);
    return paddle;
}

But when I try to addToRegion "SOUTH"

GRect initPaddle(GWindow window)
{
   GRect paddle = newGRect(200, 450, 40, 10);
   setColor(paddle, "BLACK");
   setFillColor(paddle, "BLACK");
   setFilled(paddle, true);
   addToRegion(window, paddle, "SOUTH");
  return paddle;
}

I get a blank window and the following message in the terminal.

jharvard@appliance (~/Dropbox/pset3/breakout): ./breakout
java.lang.NullPointerException
    at java.awt.Container.addImpl(Container.java:1086)
    at java.awt.Container.add(Container.java:410)
    at stanford.spl.JBEWindow.addToRegion(JBEWindow.java:101)
    at stanford.spl.GWindow_addToRegion.execute(JBECommand.java:226)
    at stanford.spl.JavaBackEnd.commandLoop(JavaBackEnd.java:625)
    at stanford.spl.JavaBackEnd.run(JavaBackEnd.java:164)
    at stanford.spl.JavaBackEnd.main(JavaBackEnd.java:136)

I have a feeling something is wrong with SPL library. Please help, I am stuck because of this.

2 Answers 2

0

You are not linking the SPL library in you compiler command. It should include -lcs like so

clang -ggdb3 -O0 -std=c99 -Wall -Werror testing.c -lcs -lm -o testing

Also if you add the -Wno-unused-variable flag you will see a warning for argc and argv because they are never used. So use:

clang -ggdb3 -O0 -std=c99 -Wall -Werror -Wunused-variable testing.c -lcs -lm -o testing

If this answers your question please accept it by clicking the gray check-mark to the left, so that it becomes green. You can also vote it up by pressing the up arrow above the check-mark. And don't forget to keep coding!

2
  • Yeah that wasn't working either, but I just took the breakout makefile and replaced the word breakout with tester, and it worked. Thanks a lot Aug 28, 2015 at 12:18
  • Glad I could help!
    – ChrisG
    Aug 28, 2015 at 12:19
0

To start with, your code shouldn't take arguments, so it should be

int main(void)
1
  • Yeah that wasn't working either, but I just took the breakout makefile and replaced the word breakout with tester, and it worked. Thank you very much Aug 28, 2015 at 12:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .