I want to built a webserver with libuv and http-parser.
The current project structure is
Makefile
/src
/main.c
/deps
/libuv (git clone of libuv)
/http-parser (git clone of http-parser)
In main.c I have defined following includes:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "uv.h"
#include "http_parser.h"
and the Makefile looks like:
LDFLAGS = -L deps/libuv
main: libuv http-parser
$(CC) src/main.c -o main.out deps/libuv/libuv.a deps/http-parser/http_parser.o $(LDFLAGS)
libuv:
$(MAKE) -C deps/libuv libuv.a
http-parser:
$(MAKE) -C deps/http-parser http_parser.o
clean:
rm deps/libuv/libuv.a
rm deps/http-parser/http_parser.o
This happens when the compiler tries to link http_parser.
make -C deps/libuv libuv.a
make[1]: `libuv.a' is up to date.
make -C deps/http-parser http_parser.o
make[1]: `http_parser.o' is up to date.
cc src/main.c -o main.out deps/libuv/libuv.a deps/http-parser/http_parser.o
src/main.c:5:10: fatal error: 'http_parser.h' file not found
#include "http_parser.h"
^
1 error generated.
make: *** [main] Error 1
When I remove the http_parser out of the includes and the Makefile than I get a weird libuv build error:
Undefined symbols for architecture x86_64:
"_CFArrayCreate", referenced from:
_uv__fsevents_init in libuv.a(fsevents.o)
"_CFRunLoopAddSource", referenced from:
_uv__cf_loop_runner in libuv.a(darwin.o)
"_CFRunLoopGetCurrent", referenced from:
_uv__cf_loop_runner in libuv.a(darwin.o)
"_CFRunLoopRemoveSource", referenced from:
_uv__cf_loop_runner in libuv.a(darwin.o)
"_CFRunLoopRun", referenced from:
_uv__cf_loop_runner in libuv.a(darwin.o)
"_CFRunLoopSourceCreate", referenced from:
_uv__platform_loop_init in libuv.a(darwin.o)
"_CFRunLoopSourceSignal", referenced from:
_uv__cf_loop_signal in libuv.a(darwin.o)
"_CFRunLoopStop", referenced from:
_uv__platform_loop_delete in libuv.a(darwin.o)
"_CFRunLoopWakeUp", referenced from:
_uv__cf_loop_signal in libuv.a(darwin.o)
"_CFStringCreateWithCString", referenced from:
_uv__fsevents_init in libuv.a(fsevents.o)
"_CFStringGetSystemEncoding", referenced from:
_uv__fsevents_init in libuv.a(fsevents.o)
"_FSEventStreamCreate", referenced from:
_uv__fsevents_init in libuv.a(fsevents.o)
"_FSEventStreamInvalidate", referenced from:
_uv__fsevents_close in libuv.a(fsevents.o)
"_FSEventStreamRelease", referenced from:
_uv__fsevents_close in libuv.a(fsevents.o)
"_FSEventStreamScheduleWithRunLoop", referenced from:
_uv__fsevents_schedule in libuv.a(fsevents.o)
"_FSEventStreamStart", referenced from:
_uv__fsevents_schedule in libuv.a(fsevents.o)
"_FSEventStreamStop", referenced from:
_uv__fsevents_close in libuv.a(fsevents.o)
"_kCFRunLoopDefaultMode", referenced from:
_uv__cf_loop_runner in libuv.a(darwin.o)
_uv__fsevents_schedule in libuv.a(fsevents.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1
I am stuck at this issue since yesterday and loosing my hope at all..
Current state of Makefile:
LDFLAGS = -Ldeps/libuv
INCLFLAGS = -Ideps/http-parser
main.o: libuv.a http-parser.o
$(CC) src/main.c $(INCLFLAGS) -o main.o deps/libuv/libuv.a deps/http-parser/http_parser.o $(LDFLAGS)
libuv.a:
$(MAKE) -C deps/libuv libuv.a
http-parser.o:
$(MAKE) -C deps/http-parser http_parser.o
clean:
rm deps/libuv/libuv.a
rm deps/http-parser/http_parser.o
verbose output:
#include "..." search starts here:
#include <...> search starts here:
deps/libuv
deps/http-parser
/usr/local/include
/usr/bin/../lib/clang/4.2/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o main.o -Ldeps/libuv /var/folders/4l/zj55m1gn289f6v04zfbl59bm0000gn/T/main-sRhCLM.o deps/libuv/libuv.a deps/http-parser/http_parser.o -lSystem /usr/bin/../lib/clang/4.2/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"_CFArrayCreate", referenced from:
_uv__fsevents_init in libuv.a(fsevents.o)
"_CFRunLoopAddSource", referenced from:
_uv__cf_loop_runner in libuv.a(darwin.o)
I suspect that http_parser.h is not in the same directory as main.c. Either copy that file there, or preferably update your INCLUDE path.
HTTP_PARSER_INCLUDE= -I/home/wherever/http_parser
main: libuv http-parser
$(CC) src/main.c -o main.out $(HTTP_PARSER_INCLUDE) deps/libuv/libuv.a deps/http-parser/http_parser.o $(LDFLAGS)
The other error you get as a result of removing http_parser.h is likely just noise as a result of not building clean to begin with. Your "main" rule as you have it declared above builds "main.out" instead of "main". That might also have something to do with Make trying to build something out of nothing.
Update - you need to add -framework CoreFoundation
to your command line to remove the linker errors.