• New to Objective-c: issue with libraries

    From modelling.data@gmail.com@21:1/5 to All on Tue Nov 10 23:25:29 2015
    Hello!

    I am new to programming, and to Objective-C. I currently take a free online course on CS, which includes C programming, and has also introduced Objective-C.

    Please, take a look at the program below, which uses Stanford Portable Library.

    I work on Mac OS 10.7.5, Xcode 4.6.3, Terminal 2.2.3, and would like to make and compile such programs within these programs. What shall I do, which headers shall I use? Shall I download them?

    **
    * bounce.c
    * Bounces a circle back and forth in a window.
    */

    // standard libraries
    #include <stdio.h>

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

    int main(void)
    {
    // instantiate window
    GWindow window = newGWindow(320, 240);

    // instantiate circle
    GOval circle = newGOval(0, 110, 20, 20);
    setColor(circle, "BLACK");
    setFilled(circle, true);
    add(window, circle);

    // initial velocity
    double velocity = 2.0;

    // bounce forever
    while (true)
    {
    // move circle along x-axis
    move(circle, velocity, 0);

    // bounce off right edge of window
    if (getX(circle) + getWidth(circle) >= getWidth(window))
    {
    velocity = -velocity;
    }

    // bounce off left edge of window
    else if (getX(circle) <= 0)
    {
    velocity = -velocity;
    }

    // linger before moving again
    pause(10);
    }
    }

    Thank you!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Pascal J. Bourguignon@21:1/5 to modelling.data@gmail.com on Wed Nov 11 19:26:23 2015
    modelling.data@gmail.com writes:

    Hello!

    I am new to programming, and to Objective-C. I currently take a free online course on CS, which includes C programming, and has also introduced Objective-C.

    Please, take a look at the program below, which uses Stanford Portable Library.

    I work on Mac OS 10.7.5, Xcode 4.6.3, Terminal 2.2.3, and would like to make and compile such programs within these programs. What shall I do, which headers
    shall I use? Shall I download them?

    Yes.

    You could write a makefile to compile your spl-example.m file:

    -----(Makefile)-----------------------------------------------------------------

    all:spl-example

    .PHONY::run get-dependencies
    get-dependencies:
    cd /usr/local/src/ ; git clone git@github.com:cs50/spl.git
    cd /usr/local/src/spl ; make && make install

    run:spl-example
    CLASSPATH=/usr/local/lib/spl.jar ./spl-example

    spl-example:spl-example.m
    gcc -o spl-example spl-example.m -lcs -lm

    clean:
    rm spl-example

    ----------------------------------------------------------------------------------

    To install spl:

    make get-dependencies

    and then to run your program:

    make run


    WFM on MacOSX and on Linux.

    --
    __Pascal Bourguignon__ http://www.informatimago.com/
    “The factory of the future will have only two employees, a man and a
    dog. The man will be there to feed the dog. The dog will be there to
    keep the man from touching the equipment.” -- Carl Bass CEO Autodesk

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)