I am making a test setup of a C static library and program. The library code, located in a subdirectory 'foo' of my project, contains the following files:
foo/foo.c:
#include <stdio.h> void foo(void) { printf("something"); } foo/foo.h:
#ifndef foo_h__ #define foo_h__ extern void foo(void); #endif My progam code is as follows:
test.c:
#include "foo.h" int main() { foo(); return 0; } I have a build script, called 'build', which contains the following:
build:
#!/bin/bash gcc -c -Wall -Werror foo/foo.c ar rcs libfoo.a foo.o gcc -static -o test test.c libfoo.a # I have also tried -L. -lfoo But when I run build, it gives me the following error:
test.c:1:17: fatal error: foo.h: No such file or directory #include "foo.h" ^ Compilation terminated It does, however, work when I omit the #include line, but I would prefer if I could use header files in my static libraries. What am I doing wrong, and how can I fix it?