1

To compile this source code with clang, we had to link "cs50" library like this: clang hello.c -lcs50

but we did not have to link "stdio". why?

/* hello.c */

#include <stdio.h>
#include <cs50.h>
int main(void)
{
    printf("state your name");
    string s = GetString();
    printf("hello, world\n");
}
4

stdio.h is a header file from the C Standard Libraries, and their implementations are in the libc.a file, due to his common and extended use, this file is automatically linked by the compiler as if the -lc argument was especified on the compiler command like this:

clang hello hello.c -lc

On the other hand, the cs50 library is and external library created by the cs50 staff, and when you want to use this library, you have to manually link it with the -lcs50 argument in the compiler command.

| improve this answer | |
  • thank you for your help! – Hakan As Feb 2 '15 at 3:17

You must log in to answer this question.

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