Menu

Build on Cygwin

2021-03-11
2021-04-03
  • STEPHEN M HARRIS

    Attempting to build POC on Cygwin.

    $ cc --version
    cc (GCC) 10.2.0

    Building the bootstrap compiler works:

    $ cd objc-bootstrap-3.3.21
    $ CC='cc -ansi ' ./configure --without-postlink --prefix=${HOME}
    $ make && make install

    Trying to build POC:
    $ cd objc-3.3.21
    $ make clean
    $ CC='cc -ansi ' ./configure --without-postlink --prefix=${HOME}
    $ make
    make compiler
    make[1]: Entering directory '/cygdrive/c/Users/stephen.harris/Downloads/POC/objc-3.3.21'
    cd src; cd objcrt; make
    make[2]: Entering directory '/cygdrive/c/Users/stephen.harris/Downloads/POC/objc-3.3.21/src/objcrt'
    objc -q -c Object.m -DNDEBUG -O2 -noI
    ar cr objcrt.a Object.o
    objc -q -c Block.m -DNDEBUG -O2 -noI
    /usr/include/cygwin/signal.h:49: fatal: syntax error "attribute"
    make[2]: [Makefile:43: Block.o] Error 1
    make[2]: Leaving directory '/cygdrive/c/Users/stephen.harris/Downloads/POC/objc-3.3.21/src/objcrt'
    make[1]:
    [Makefile:27: objcrt] Error 2
    make[1]: Leaving directory '/cygdrive/c/Users/stephen.harris/Downloads/POC/objc-3.3.21'
    make: *** [Makefile:19: default] Error 2

    I think the above is saying the objc bootstrap compiler does not understand attribute. I dont know how to work around this.

     
  • David Stes

    David Stes - 2021-03-21

    Hi Stephen,

    Thanks for the feedback and for reporting this issue.

    The current version is objc-3.3.23.tar.gz available at my home page or at https://sourceforge.net/projects/objc/files/

    In that package you'll see that I built the compiler a longtime ago succesfully on CYGWIN32:

    i586-cygwin32-windows95 (gcc)

    On Windows 10 x64 (64bit) I have the option to install either CYGWIN64 with their setup program setup-x86_64.exe or their 32bit version with setup-x86.exe .

    I first tried the 64bit version and I can reproduce your messages; they will be fixed in a future release of the compiler.

    Then I tried to install CYGWIN32 with the setup-x86.exe

    During the install I selected the following packages :

    $ byacc -V
    byacc - 1.9 20170430

    $ flex --version
    flex 2.6.4

    $ gcc --version
    gcc (GCC) 10.2.0

    $ make --version
    GNU Make 4.3

    For their version of flex I also installed GNU m4 although that as far as I know I don't use m4 but I think flex requires the m4.

    Anyway that installs CYGWIN32 configured to produce 32bit executables.

    The best solution here would be if I build some day a binary package of the compiler for cygwin32 so that you can start with that compiler.

    Using the bootstrap compiler is a little bit difficult here.

    Anyway it worked for me as follows :

    $ ./configure -with-postlink i386-unknown-cygwin
    $ make
    $ make install

    Note that I use --with-postlink which is unusual and also the opposite of the flag you posted (without-postlink).

    I once wrote a discussion of this in the compiler manual :

    http://users.telenet.be/stes/manual/index.html

    You can find a discussion on postlink in the manual -- I hope it make sense since it is fairly sophisticated runtime specifics on how to do a runtime initialization and send all classes for example +initialize or to make sure that all classes get initialized on startup.

    So in the above I try to force to use the postlink linker model.

    The postlink model requires a small helper file called _prelink.o

    You can build that in the objc-3.3.23 sources - cd to src/objc and do:

    $ make _prelink.o
    $ cp _prelink.o /usr/local/lib/

    That copies the _prelink.o file required by postlink.

    The next difficulty was that the header file /usr/include/ctype.h also for the 32bit case contains some difficult expression I got rid of that by doing a:

    $ diff /usr/include/ctype.h /usr/include/ctype.h.orig
    156c156
    < # if 0


    if defined(GNUC)

    So I first made a copy ctype.h.orig and then I ifdef 0 a macro definition of tolower()

    That's because I just wanted the regular tolower() function definition for now.

    Given the above bootstrap compiler and header file modification I build

    objc-3.3.23

    as follows

    $ ./configure --with-postlink i386-unknown-cygwin FINAL_AR=echo

    The FINAL_AR=echo may be a recently introduced bug - I have to look into that.

    Note that for the compiler I configure --with-postlink.

    Then I do a make and make install and I get:

    $ objc --version
    Portable Object Compiler - objc-3.3.23 - i386-unknown-cygwin
    Distributed under the terms of the GNU LGPL.

    It builds the Object Pak and Computer Algebra Kit for CYGWIN32 and the compiler.

    The entire process can be simpler if I create CYGWIN32 (and eventually CYGWIN64) packages which can be done.

    The bootstrap package is nice but using / providing binary packages is probably better and simpler to get started compiling the compiler.

    David Stes

     
  • David Stes

    David Stes - 2021-03-21

    For a discussion of automatic runtime initialization (--without-postlink == automatic) and postlink runtime initialization (--with-postlink) see the manual.

    This is because our implementation of automatic runtime initialization depends on the availability of an ANSI C compiler that follows the so-called common storage linker model (see Appendix 10.6 in [Kernighan and Ritchie, 1988]).

    It seems the gcc 10.2 setup is using the nocommon storage setup in CYGWIN32.

    Presumably this was a choice when configuring/building gcc 10.2, since I think gcc like all UNIX compilers supports common storage, presumably if you test gcc 10.2 on say Linux or some UNIX system it'll be using the automatic runtime initialization for Portable Object Compiler so it's not in se specific to gcc 10.2.

    Anyway Portable Object Compiler can work with --with-postlink on compilers that require this or that are setup to require this.

     
    • STEPHEN M HARRIS

      I decided I was just beating myself up by trying to make Cygwin work. Every successful compile that uses GCCOBJC ends in a segfault.

      I wiped that machine and loaded Debian. I have Stephen Kochan's book 'Programming in Objective-C' and am using it or other programs that are just slightly above the level of Hello World.

      I built POC on Debian, no sweat. When I compile with GCCOBJC I get a flurry of warnings about free and init, and when I execute I continue to get segfaults. Switching to POC spits out a syntax error about a ';' in GCC's Object/objc.h. BTW - I had thought POC was sending regular C to CC for compilation, so I wonder why GCC is looking at an objc header? 'gcc --std=c89' I thought was sufficient to compile POC output.

      I would normally say I am not intensely stupid and should be able to figure this out, but, that does not seem to be the case. Very frustrating.

       
  • STEPHEN M HARRIS

    /* main003.m

    Objective-C hello world-type program

    compile:
    $ gcc main003.m -o gnu_prog003 -l objc

    compile POC:
    $ ${HOME}/bin/objc -verbose -import -B${HOME} main003.m -o poc_prog004
    */

    /
    stolen from example written by Pascal Bourguignon
    /

    import <stdio.h></stdio.h>

    import <objc object.h=""></objc>

    / -=-=-=-=- @interface section /

    @interface Greeter: Object {
    /
    normally instance variables would be declared here,
    but these are none used in this example
    /
    }

    -(void) greet;

    @end

    / -=-=-=-=- @implementation section /

    @implementation Greeter

    -(void) greet {

    ifdef PORTABLE_OBJC

    printf("Hello World! - POC Obj-C\n");
    

    else

    printf("Hello World! - GNU Obj-C\n");
    

    endif

    }

    @end

    / -=-=-=-=- program section /

    int main(int argc, const char *argv[])
    {
    id myGreeter;
    myGreeter = [Greeter alloc];
    myGreeter = [myGreeter init];

    [myGreeter greet];
    
    [myGreeter free];
    return 0;
    

    }

     
  • STEPHEN M HARRIS

    $ gcc main003.m -o gnu_prog003 -l objc
    main003.m: In function ‘main’:
    main003.m:51:2: warning: ‘Greeter’ may not respond to ‘+alloc’
    myGreeter = [Greeter alloc];
    ^~~~~~~~~
    main003.m:51:2: warning: (Messages without a matching method signature
    main003.m:51:2: warning: will be assumed to return ‘id’ and accept
    main003.m:51:2: warning: ‘...’ as arguments.)
    main003.m:52:2: warning: no ‘-init’ method found
    myGreeter = [myGreeter init];
    ^~~~~~~~~
    main003.m:56:2: warning: no ‘-free’ method found
    [myGreeter free];
    ^
    $ ls -la gnu_prog003
    -rwxr-xr-x 1 steveharris steveharris 18248 Apr 3 18:08 gnu_prog003
    $ ./gnu_prog003
    Segmentation fault

     
  • STEPHEN M HARRIS

    $ ${HOME}/bin/objc -import -B${HOME} main003.m -o poc_prog004
    Portable Object Compiler 3.3.24 (c) 1997-2021.
    Distributed under the terms of the GNU LGPL.
    /usr/lib/gcc/x86_64-linux-gnu/8/include/objc/objc.h:94: fatal: syntax error ";"

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.