Search code examples
cwindowsgcccygwincs50

gcc compiler error: "cannot find -lcs50 collect2: Id returned 1 exit status"


I have a problem in 'c' language inside compiling with gcc.

  1. I am using "Cygwin" with (gcc-core, gcc-g++, gdb, make & other supportive packages) inside windows xp.
  2. I installed "Cygwin" on this path "C:\Cygwin\".
  3. My home directory: "C:\Cygwin\home\Bhanu Pratap"
  4. I copied "cs50.h" and "cs50.c" inside my working directory which is also under "C:\Cygwin\home\Bhanu Pratap".

This is code inside my hello.c file

#include "cs50.h"
#include <stdio.h>
int
main(void){
  string name = "David";
  printf("O hai, %s!\n", name);
}

This is command under bash (Cygwin)

gcc -o hello hello.c -lc50

I get this error:

/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/id: cannot find -lcs50
collect2: Id returned 1 exit status

Please help me where i am wrong?


Solution

  • To be able to use -lcs50, you'll first need to build that library (cs50) from its source code (cs50.c).

    Alternatively, you could simply:

    gcc -o hello hello.c cs50.c
    

    assuming cs50.c doesn't have other dependencies.