4

There's a similar question about running breakout on Linux variants: Can't run Breakout outside of appliance

My question is specifically about compiling breakout (and hence SPL) on Mac OS X.

So far I have tried running make in the source directory, but the compiler complains that the SPL (spl/lib/libcs.a) is not built for the current architecture, e.g.:

MacBook-Pro:Breakout luke$ make
clang -ggdb3 -Ispl/include -O0 -std=c99 -Wall -Werror -Wno-unused-variable -o breakout breakout.c -Lspl/lib -lcs -lm
ld: warning: ignoring file spl/lib/libcs.a, file was built for archive which is not the architecture being linked (x86_64): spl/lib/libcs.a
Undefined symbols for architecture x86_64:
  "_add", referenced from:
      _main_ in breakout-a98e8b.o
      _initBricks in breakout-a98e8b.o
      _initBall in breakout-a98e8b.o
      _initPaddle in breakout-a98e8b.o
      _initScoreboard in breakout-a98e8b.o
      _initLives in breakout-a98e8b.o
  "_closeGWindow", referenced from:
  _main_ in breakout-a98e8b.o
  "_getEventType", referenced from:
      _main_ in breakout-a98e8b.o
  "_getGObjectAt", referenced from:
      _detectCollision in breakout-a98e8b.o
  "_getHeightGeneric", referenced from:
      _updateScoreboard in breakout-a98e8b.o
  "_getNextEvent", referenced from:
      _main_ in breakout-a98e8b.o
  "_getType", referenced from:
      _main_ in breakout-a98e8b.o
  "_getWidthGeneric", referenced from:
      _updateScoreboard in breakout-a98e8b.o
  "_getXGeneric", referenced from:
      _main_ in breakout-a98e8b.o
      _detectCollision in breakout-a98e8b.o
  "_getYGeneric", referenced from:
      _main_ in breakout-a98e8b.o
      _detectCollision in breakout-a98e8b.o
  "_main", referenced from:
     implicit entry/start for main executable
     (maybe you meant: _main_)
  "_move", referenced from:
      _main_ in breakout-a98e8b.o
  "_newGLabel", referenced from:
      _main_ in breakout-a98e8b.o
      _initScoreboard in breakout-a98e8b.o
      _initLives in breakout-a98e8b.o
  "_newGOval", referenced from:
      _initBall in breakout-a98e8b.o
  "_newGRect", referenced from:
      _initBricks in breakout-a98e8b.o
      _initPaddle in breakout-a98e8b.o
  "_newGWindow", referenced from:
      _main_ in breakout-a98e8b.o
  "_removeGWindow", referenced from:
      _main_ in breakout-a98e8b.o
  "_setColor", referenced from:
      _initBricks in breakout-a98e8b.o
      _initPaddle in breakout-a98e8b.o
  "_setFilled", referenced from:
      _initBricks in breakout-a98e8b.o
      _initPaddle in breakout-a98e8b.o
  "_setFont", referenced from:
      _main_ in breakout-a98e8b.o
      _initScoreboard in breakout-a98e8b.o
      _initLives in breakout-a98e8b.o
  "_setLabel", referenced from:
      _updateScoreboard in breakout-a98e8b.o
      _updateLives in breakout-a98e8b.o
  "_setLocation", referenced from:
      _main_ in breakout-a98e8b.o
      _updateScoreboard in breakout-a98e8b.o
      _updateLives in breakout-a98e8b.o
  "_waitForClick", referenced from:
      _main_ in breakout-a98e8b.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [breakout] Error 1

Thought this might be because SPL is 32 bit, I tried compiling for 32-bit mode by adding a -m32 option for clang, but that results in similar errors:

MacBook-Pro:pset4 luke$ clang -ggdb3 -Ispl/include -O0 -std=c99 -Wall -Werror -Wno-unused-variable -o breakout -m32 breakout.c -Lspl/lib -lcs -lm
ld: warning: ignoring file spl/lib/libcs.a, file was built for archive which is not the architecture being linked (i386): spl/lib/libcs.a
Undefined symbols for architecture i386:
  "_add", referenced from:
      _initScoreboard in breakout-007735.o
      _initBricks in breakout-007735.o
      _initBall in breakout-007735.o
      _initPaddle in breakout-007735.o
      _initLives in breakout-007735.o

It seems that SPL is compiled with some architecture that is not compatible with OS X, although I would have thought it would be standard.

Update 25 July '14

Marty Stepp responded to my email requesting C source:

The libraries are nowadays distributed as source here:

http://stanford.edu/~stepp/cppdoc/

This site also contains the latest documentation on how to use the libraries.

This links to what appears to be C++ code only. This doesn't seem to be directly compatible with C. I'm assuming there is no official C version. I'm guessing the version provided for CS50 is from another source.

  • 3
    SPL is not the Standard Portable Library that you've downloaded. It's the Stanford Portable Library, which is like the CS50 Library in that it was written specifically for Stanford's intro CS classes so the students could use a graphical interface without having to write it themselves. Not sure how portable it is as what we've been given is compiled code (under Linux), not source code. – curiouskiwi Jul 14 '14 at 1:16
  • Thanks @curiouskiwi, that explains a lot. Rooting around for Stanford Portable Library turned up a paper (cs.stanford.edu/people/eroberts/papers/ITiCSE-2013/…) and some source code at (web.stanford.edu/class/cs106b/cppdoc). Nothing usable yet. – Luke Van In Jul 14 '14 at 8:03
  • so how did you compile this source code for your mac? @Luke Van In. – user1567 Jul 20 '14 at 14:46
  • @arbayong I still have not been able to compile the code. It appears that while the SPL library may portable, the C source code is not necessarily open source. It should be fairly trivial to translate the C++ into a C interface, I just don't have time to do it myself at the moment. – Luke Van In Jul 21 '14 at 10:09
  • 2
    Perhaps your best bet is to contact Marty Stepp who maintains the SPL. (stepp AT stanford DOT edu). The project is only in beta and there may be unpublished stuff that he knows about. – curiouskiwi Jul 21 '14 at 11:24
1

Does this work??

https://www.dropbox.com/s/8g3uo5biu2g4x7r/libcs.a

[30 char limit blahhhh]

| improve this answer | |
  • 1
    Thanks Rob, it works perfectly. – Luke Van In Jul 29 '14 at 22:52
  • 1
    Hey @LukeVanIn , I also want to run breakout on my MAc computer. Can you provide me the file libcs.a because the dropbox link above doesnt work, it gives a 404 – Confused Guy Aug 23 '14 at 5:27
  • can you share the libcs.a file again so I can get it running on my mac please? – intel3 Nov 16 '14 at 16:25
  • @Rob Bowden would you happen to have an Ubuntu compiled version? I'm having the same issue in Ubuntu 14.04. – abelinux Dec 8 '14 at 20:18
  • @Rob-Bowden, I would like to try this port as well. Could you share that link again? The location above returns 404 atm. Thank you sir! – Jeff Couch Feb 5 '15 at 15:24
4
+25

As such, the Stanford Portable Library is under a GNU license, which makes it legal for us (or in fact, me) to redistribute it to you, or anyone else, as stated by the license:

/*********************************************************************/
/* Stanford Portable Library /
/ Copyright (C) 2013 by Eric Roberts  /
/ /
/ This program is free software: you can redistribute it and/or modify /
/ it under the terms of the GNU General Public License as published by /
/ the Free Software Foundation, either version 3 of the License, or /
/ (at your option) any later version. /
/ /
/ This program is distributed in the hope that it will be useful, /
/ but WITHOUT ANY WARRANTY; without even the implied warranty of /
/ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
/ GNU General Public License for more details. /
/ /
/ You should have received a copy of the GNU General Public License /
/ along with this program. If not, see http://www.gnu.org/licenses/. */
/*********************************************************************/
Because I couldn't myself find a version of the SPL online, I had to decompile it myself, and well this was the hence obtained version of the folder:

The Dropbox Folder

This is presently hosted at Dropbox, as I don't know (if possible) as to how to host a folder using Stack Exchange.

Full thanks to Eric Roberts for creating the SPL library(and making it GNU-licensed) and JD(Java Decompiler)

Appendix

After @LukeVanIn reported that the SPL library I provided failed to do his job, I tried to redo it myself on my Mac which easily ran my breakout(OS X Mavericks), so I'm supposing that he probably has made some minor mistake or something thats preventing him from being able to run breakout on his computer, whereas my version(I'm quite sure) runs on a macintosh quite easily, so, try to use this one and see if mine is running...

MY BREAKOUT FOLDER

How to Use the Folder(s)

Because @LukeVanIn and a few others have been facing problems as to how to compile it and are still unsuccessful, here's how to do it!

  1. Download the SPL folder from Dropbox(SPL) and rename it to "spl" without the qoutes.
  2. Open up terminal and head over to the folder /usr/include/ by cd /usr/include
  3. Copy the SPL folder(now renamed to spl) by using cp -r [Source folder] [destination directory] . For more on this see this link.
  4. Now, check if the folder got copied successfully by doing ls and checking if a spl folder exists. If yes, proceed, else, move to step 3 back.
  5. Now head back to your breakout folder and run Make if you have clang installed. Hope you are successful now!

:)

Happy Coding!

| improve this answer | |
  • Thanks @Nib. I'll try it out in a bit and accept your answer if it works. – Luke Van In Jul 21 '14 at 15:09
  • @LukeVanIn, it worked alright for me, but I transferred it only to my Ubuntu, so, pardon me if it doesn't work for the OS X. In that case, you can always try to decompile the SPL yourself and well, enjoy! – Nib Jul 21 '14 at 15:57
  • Unfortunately this one does not seem to work on Mac either. It seems to be the same version as the one provided with the problem set. I followed your advice and looked at decompiling the SPL Jar. The results revealed interesting information about the Java implementation of SPL, but I could not see a way to produce the necessary C source files, or library. – Luke Van In Jul 21 '14 at 17:11
  • Well, that's odd, I have my Mac fired up and running breakout using this SPL version only, @LukeVanIn wait for a day, I'll show you all my code so that you can cross reference it – Nib Jul 21 '14 at 17:43
  • 1
    @LukeVanIn I can :P – Nib Jul 28 '14 at 14:24
1

This is what i did to get this working on osx el capitan. (I already have a working cs50 library installed)

you will need to install git first https://git-scm.com/

open a terminal and clone the spl git repo

user@mbp:~/$ git clone https://github.com/cs50/spl.git
user@mbp:~/$ cd spl
user@mbp:~/spl$ make

this will compile the libcs.a library and the spl.jar file.

You can now run

user@mbp:~/spl$ sudo make install

to install these files, which will place them in the /usr/local/lib directory.

You need the spl.jar file in the same directory where you will run your breakout binary so i just copied it to my breakout directory:

user@mbp:~/spl$ cd ~/breakout
user@mbp:~/breakout$ cp /usr/local/lib/spl.jar .

then i compiled it with all the arguments needed for the cs50 and libcs libraries

user@mbp:~/breakout$ gcc breakout.c -o breakout -I /usr/local/include -L /usr/local/lib -lcs50 -lcs

Now i can run the binary with user@mbp:~/breakout$ ./breakout

| improve this answer | |
0

I thought it might be a good idea to learn Objective-C and use Cocoa to write GUI applications that run on Mac as this answer (and really many answers online) suggests.

| improve this answer | |
  • I agree! I code iOS apps with Objective-C daily. I'm more interested in the cross platform capabilities of SPL, for running breakout on Mac, and maybe even Windows (although it lacks POSIX which I'm not sure is required by SPL). I also think this may be helpful to other students as there have been a few (not many) questions asking the same on Reddit and Facebook. – Luke Van In Jul 26 '14 at 16:48
  • 2
    It's sad that it doesn't work easily on other platforms, but what's more sad is that we asked the professor online on the Facebook group whether there's a way to get it up and running on other platforms, but unfortunately he didn't answer us. – Kareem Jul 26 '14 at 16:51
  • @Kareem, I have raised this issue to David sir personally – Nib Jul 26 '14 at 17:18

You must log in to answer this question.

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