1

I am trying to compile a c program with cygwin and gcc. I am using Windows 8.1

I get the following error ...

/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../lib/libcygwin.a(libcmain.o): In function `main':
/usr/src/debug/cygwin-1.7.35-1/winsup/cygwin/lib/libcmain.c:39: undefined reference to `WinMain'
/usr/src/debug/cygwin-1.7.35-1/winsup/cygwin/lib/libcmain.c:39:(.text.startup+0x7e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `WinMain'
collect2: error: ld returned 1 exit status

Does anyone know what is going on here?

My code looks like ... (taken from link removed... page full of ads)

edit: link : http://c.learncodethehardway.org/book/ex14.html

#include <stdio.h>
#include <ctype.h>

// forward declarations
int can_print_it(char ch);
void print_letters(char arg[]);

void print_arguments(int argc, char *argv[])
{
    int i = 0;

    for(i = 0; i < argc; i++) {
        print_letters(argv[i]);
    }
}

void print_letters(char arg[])
{
    int i = 0;

    for(i = 0; arg[i] != '\0'; i++) {
        char ch = arg[i];

        if(can_print_it(ch)) {
            printf("'%c' == %d ", ch, ch);
        }
    }

    printf("\n");
}

int can_print_it(char ch)
{
    return isalpha(ch) || isblank(ch);
}


int main(int argc, char *argv[])
{
    print_arguments(argc, argv);
    return 0;
}

On the command line I run ...

gcc learn.c -Wall -o learnc.exe

I could run my code yesterday. I have not made any change to my system settings or file structure.

Thanks!

user1795370
  • 332
  • 2
  • 4
  • 18
  • [Possible Duplicate](http://stackoverflow.com/questions/23918318/undefined-reference-to-winmain-in-cygwin) – Dayal rai Apr 23 '15 at 05:45
  • I looked into that and it didn't help with this problem. When I ran with -c the file that created could not be executed – user1795370 Apr 23 '15 at 05:46
  • The link you provide as a source seems to be just an ad page. – Eric J. Apr 23 '15 at 05:47
  • sorry, I've linked the appropriate location – user1795370 Apr 23 '15 at 05:49
  • WinMain in Cygwin???!!! You must be joking :-) – VolAnd Apr 23 '15 at 05:57
  • No joke! I tried the -c flag, but when I tried to run the executable I got the error "cannot execute binary file" – user1795370 Apr 23 '15 at 05:58
  • Well if it works on a different machine then you know where the problem is. – 2501 Apr 23 '15 at 05:59
  • 1
    I've only ever run it on one machine. Last night it worked on this computer, and tonight it does not. Same computer – user1795370 Apr 23 '15 at 06:04
  • It may be that some part of the configuration did change, e.g. the PATH environment variable, which would affect which gcc.exe is used, and where libraries and DLLs are found. It looks to me like your Cygwin installation is broken, and perhaps only works with precisely the correct PATH setting. If you want to debug this further, run your compile command again with the "-v" option and copy/paste all output. However, do you need to use Cygwin? Mingw does most of the same things, but it's much lighter, and I find it works much better. – Jack Whitham Apr 23 '15 at 09:29

0 Answers0