libuvとhttp-parserを使用して Web サーバーを構築したいと考えています。
現在のプロジェクト構造は
Makefile
/src
/main.c
/deps
/libuv (git clone of libuv)
/http-parser (git clone of http-parser)
main.c で、次のインクルードを定義しました。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "uv.h"
#include "http_parser.h"
Makefile は次のようになります。
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
これは、コンパイラが 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
http_parser をインクルードと Makefile から削除すると、奇妙な libuv ビルド エラーが発生します。
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
昨日からこの問題で立ち往生しており、希望をまったく失っています..
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
詳細な出力:
#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)