Installing:
Install Xcode Command Line Toolsxcode-select --install
Click “Install” to download and install Xcode Command Line Tools.
Compiling:
Using Make utility:
To buld:
make HelloWorld
To run:
./HelloWorld
Using compiler:
clang HelloWorld.c or gcc HelloWorld.c for GCC compiler
CS50:
How do instal cs50.h library?
Test code:
#include <stdio.h>
#include <cs50.h>
int main() {
printf("Your Name, please: \n");
string s = GetString();
printf("Your Name is: %s! \n", s);
return 0;
}
Try to compile:
clang YourName.c -lcs50
-l means to link an objecting code into compiling phase. Hey, link the cs50 precompiled objecting code into target project. Put all -l parameters at the end of line.
This line will create an a.out file. Initially Clang compiler build the target program into a.out file. To rename that file into name of source file project we can use -o <fileName>
Compile one more time:
for gcc compiler use:
gcc -o YourName YourName.c -lcs50
Run the program:
./YourName
Vita!
Miscellaneous:
/usr/include
/usr/local/include
/usr/local/lib
Help me!
clang -help
Only run the preprocessor.
clang -E <fileName>
Only run preprocess and compilation steps. Compile to assembler.
clang -S <fileName>
Only run preprocess, compile, and assemble steps.
clang -c <fileName>
-lm link math
-Wall or -w enable all warnings
-Werror stop when get warning
-ggdb include debugger data
What is .a file?
.a files are static libraries
No comments:
Post a Comment