Do not control library linking with clang

I want to create a web server with libuv and http-parser .

Current project structure

Makefile /src /main.c /deps /libuv (git clone of libuv) /http-parser (git clone of http-parser) 

In main.c, I defined the following:

 #include <stdio.h> #include <stdlib.h> #include <string.h> #include "uv.h" #include "http_parser.h" 

and the makefile looks like this:

 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 bind 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 http_parser from inclusions and Makefile, I get a strange 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 was stuck on this issue from yesterday and generally lost my hope.

Current Makefile Status:

 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 

detailed 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) 
+4
source share
1 answer

I suspect http_parser.h is not in the same directory as main.c. Either copy this file, 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) 

Another error you get as a result of removing http_parser.h is most likely a noise due to the fact that it was not clean from the very beginning. Your "main" rule, as you stated above, builds "main.out" instead of "main". It may 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 linker errors.

+2
source

All Articles