https://github.com/springmeyer/learn-c
Learning C from scratch (compilers, linkers, build systems)
https://github.com/springmeyer/learn-c
Last synced: 10 months ago
JSON representation
Learning C from scratch (compilers, linkers, build systems)
- Host: GitHub
- URL: https://github.com/springmeyer/learn-c
- Owner: springmeyer
- Created: 2015-12-04T20:11:00.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-07-31T23:05:30.000Z (almost 9 years ago)
- Last Synced: 2025-04-12T20:03:07.645Z (about 1 year ago)
- Language: Shell
- Homepage:
- Size: 7.81 KB
- Stars: 11
- Watchers: 0
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# learn c
Examples of hello world C programs, libraries, headers and details of how to compile, link, and run from scratch (without using a build system like Make, cmake, or gyp).
[](https://travis-ci.org/springmeyer/learn-c)
## Requires
- clang compiler
## Usage
To build all examples:
```sh
./build-all.sh
```
To test all examples:
```sh
./test-all.sh
```
To build and test a specific example:
```sh
cd step_1
./build.sh
./test.sh
```
To build and test a specific example without causing your
working directory to change:
```sh
(cd step_1 && ./build.sh && ./test.sh)
```
### definitions
#### compiler
Command line tool, like gcc or clang, that can compile and link code
C compilers are gcc and clang. C++ compilers are g++ and clang++.
#### linker
The linker is usually called `ld`. But you don't need to invoke it directly. Instead it gets invoked by the compiler.
#### compile
Turn C or C++ code into `.o` (object files)
#### link
Turn object files into either and executable or a library
#### Build system
Not going to find one here! Actually that is a lie. Here we use bash scripts called `build.sh` to invoke the compiler to compile and link. For larger projects you'll want to use a build system like cmake, ninja, make, or gyp that is able to intelligently recompile and link only when certain files have changed.
#### Extra handy tools
- `nm` shows symbols (aka functions/methods) inside a library
- `otool -L` shows what dynamic a program links to on OS X
- `ldd` shows what dynamic a program links to on linux
- `readelf -d` shows rpaths and other special things about a library on linux