Skip to content

Commit

Permalink
Continue notes and simple example
Browse files Browse the repository at this point in the history
Notes are a work-in-progress.
  • Loading branch information
margold committed Jun 15, 2016
1 parent c722e7d commit 8b5b877
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

# -03: highest (?) optimization level. if result is hard to follow, use -00 for no optimization. Doesn't work with cc?
# -Werror: treat warnings as errors

# Having spaces around the = sign is ok here (in contrast to in the shell)
P=example
OBJECTS=
CFLAGS = -g -Wall -Werror
LDLIBS=
CFLAGS=`pkg-config --cflags gsl` -g -Wall -Werror # pkg-config will add the include path (I guess these are compiler flags?)
LDLIBS=`pkg-config --libs gsl` # pkg-config will add the lib path and individual -l lib links (I guess these are linker flags?)
CC=cc

$(P): $(OBJECTS)
Expand Down
33 changes: 21 additions & 12 deletions NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
- what does it mean when brew installs a C library? ( "as C authors, the package manager is a key means by which we can get libraries for folding into our work") How does it play with apple-installed libraries of apps? (like gcc or c libraries) How do you even install C libraries on OSX? (`brew search libcurl` yields nothing)
- difference between terminal (eg. mintty on Windows) and shell (eg. bash)

# Notes
- gprof (part of binutils; http://www.gnu.org/software/binutils/binutils.html) apparently not supported on OSX? use dtrace instead.

# Tentative goals
- wrap aqbanking for python
- ??? (others!)

# C "stack"
- compiler, POSIX tools, packet manager (for (ISO (?) standard or not) libraries and more POSIX tools)

Expand All @@ -35,24 +28,35 @@ LD_LIBRARY_PATH (Linux/Cygwin) or DYLD_LIBRARY_PATH(OSX): (additional) search pa

# Tools
- See what libraries a program or dynamically linked library depends on:
• Cygwin:cygcheck libxx.dll
• Linux:ldd libxx.so
• Cygwin: cygcheck libxx.dll
• Linux: ldd libxx.so
• Mac: otool -L libxx.dylib
- cscope (http://cscope.sourceforge.net/): according to Ouz, de-facto standard (b/c only?) C project browsing tool (i.e., "better grep")
- gprof (part of binutils; http://www.gnu.org/software/binutils/binutils.html) apparently not supported on OSX? use dtrace instead.

## Autotools
./configure && make && (sudo) make install
./configure takes certain configuration flags, such as `--prefix`

# Misc Tools
- `env`: list all env variables known to the shell
- `ack`/`ag`: faster `grep` (installed with brew)

# Various info
- Cygwin: run by Red Hat (?). Uses a C library providing POSIX functions on Windows (cygwin1.dll apparently?). The library hides some differences between Windows and POSIX systems (eg. unified file system vs distinct drives). Tools that are used on POSIX systems (ls, bash, grep, make, etc) are compiled by linking to this library. A package manager is allowing the user to install all or a subset of these tools.
- POSIX: specifies how the shell, a set of commands (ls, grep, ...), and a set of C libraries should work; specifies a set of commands and libraries that needs to be available to the developer on the system.

# Finding libraries with pkg-config
- pkg-config is looking for `libname.pc` files
-
## brew-installed libraries
## Brew-installed libraries
apparently it matters if brew-installed pkg-config is used (??)
```
margold@home-macbook ~/RC/aqbanking-5.6.10 $ ls -lh `which pkg-config`
lrwxr-xr-x 1 margold brew 42B Jun 6 16:10 /usr/local/bin/pkg-config -> ../Cellar/pkg-config/0.29.1/bin/pkg-config
```

when it works:
1. when it works:
```
margold@home-macbook ~ $ pkg-config --libs libpng
-L/usr/local/Cellar/libpng/1.6.17/lib -lpng16
Expand All @@ -63,7 +67,7 @@ margold@home-macbook ~ $ brew ls --verbose libpng | grep pc
/usr/local/Cellar/libpng/1.6.17/lib/pkgconfig/libpng16.pc
```

when it doesn't
2. when it doesn't
```
margold@home-macbook ~ $ pkg-config --libs gmp
Package gmp was not found in the pkg-config search path.
Expand All @@ -74,3 +78,8 @@ No package 'gmp' found
# no .pc file was installed by brew
brew ls --verbose gmp | grep pc
```
This is because gmp project doesn't include a .pc file (see repository: https://gmplib.org/repo/gmp-6.1/file/tip)
Solutions:
- register gmp manually with pkg-config (eg. with https://gist.github.com/douglas-vaz/7399155 and https://gist.github.com/douglas-vaz/7397347)
- add linker flags manually
- create gmp.pc file in brew formula .rb file? (https://github.com/Homebrew/homebrew-core/blob/master/Formula/gmp.rb)
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#### Overview
This is a set of notes for working with a common c "stack". Work in progress.
6 changes: 6 additions & 0 deletions example.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <stdlib.h>
#include <gsl/gsl_cdf.h>
#include <stdio.h> // paste stdio.h (declaration for printf) here
// the linker will need to find stdio library (at which step?)
// it will know to include the library b/c of -lc flag (for including libc, implicit)
Expand All @@ -9,6 +11,10 @@ int main(int argc, char *argv[])
char cat2[] = "Adacat";
printf("There are %d cats: ", count);
printf("%s and %s <3\n", cat1, cat2);
printf("Also, a gsl test: %g\n", gsl_cdf_gaussian_P(-1.96, 1));

char *home = getenv("HOME");
printf("home is %s\n", home);

return 0;
}

0 comments on commit 8b5b877

Please sign in to comment.