不使用clang管理链接库

不使用clang管理链接库,c,compiler-construction,linker,makefile,clang,C,Compiler Construction,Linker,Makefile,Clang,我想用和构建一个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

我想用和构建一个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"
当编译器尝试链接http_解析器时会发生这种情况

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
当我从includes和Makefile中删除http_解析器时,我会得到一个奇怪的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
从昨天起我就一直在这个问题上纠缠不休,完全失去了希望

生成文件的当前状态:

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)
#包括“…”搜索从这里开始:
#包括搜索从这里开始:
副署长/图书馆
deps/http解析器
/usr/本地/包括
/usr/bin/。/lib/clang/4.2/include
/usr/包括
/系统/库/框架(框架目录)
/库/框架(框架目录)
搜索列表结束。
“/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/libg/rt.osx.a
架构x86_64的未定义符号:
“\u CFArrayCreate”,引用自:
_libuv.a(fsevents.o)中的uv\ufsevents\uinit
“\CFRunLoopAddSource”,引用自:
_libuv.a(darwin.o)中的uv\cf\u循环运行程序

我怀疑http\u parser.h与main.c不在同一目录中。要么将该文件复制到那里,要么最好更新包含路径

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)
删除http_parser.h时出现的另一个错误可能是由于没有从一开始就构建干净而产生的噪音。上面声明的“main”规则将生成“main.out”而不是“main”。这也可能与Make试图从无到有地构建一些东西有关


更新-您需要将
-framework CoreFoundation
添加到命令行以删除链接器错误。

关于include标志,您似乎是对的。http_解析器不再有错误,但链接libuv的错误仍然存在。我已经添加了更新的Makefile,它现在使用与输出文件相同的规则名称您在Mac上,对吗?您需要将“-framework CoreFoundation”添加到您的命令行中。谢谢,这几乎就是它。我添加了您的标志,但仍有一些未定义的符号。因此,我查看了libuv makefile以了解更多的框架,并在这里找到了它们:现在它可以工作了。谢谢!
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)