1

I am not too familiar with how linking works, so apologies ahead of time if I do not have enough detail.

I have installed the bsd library with sudo apt-get install libbsd-dev on ubuntu 11.10 I am relatively certain this has been installed, as the man function for heap/mergesort exists (the functions I am looking for)

The C file that I wish to compile has #include <bsd/stdlib.h> at the top of the file. I am also #include <stdlib.h>.

The Makefile works for other libraries, including time.h gives me struct timespec

Is there some error in assuming where apt-get installs libbsd to? Is the second stdlib somehow clashing?

Once again, apologies for the sparse detail.

Code for Makefile below:

CFLAGS=-g -O2 -Wall -Wextra -Isrc -rdynamic -DNDEBUG $(OPTFLAGS)
LIBS=-llcthw -lbsd -lrt -ldl  $(OPTLIBS)
LDLIBS=-lbsd -lrt -ldl
PREFIX?=/usr/local

SOURCES=$(wildcard src/**/*.c src/*.c)
OBJECTS=$(patsubst %.c,%.o,$(SOURCES))

TEST_SRC=$(wildcard tests/*_tests.c)
TESTS=$(patsubst %.c,%,$(TEST_SRC))

TARGET=build/liblcthw.a
SO_TARGET=$(patsubst %.a,%.so,$(TARGET))

all : $(TARGET) $(SO_TARGET) tests
4

1 回答 1

2

下面的补丁呢?此补丁适用于http://c.learncodethehardway.org/book/ex28.html中的 Makefile

--- orig/Makefile   2013-11-15 17:58:44.571824670 +0900
+++ Makefile    2013-11-15 17:59:37.315825864 +0900
@@ -1,5 +1,6 @@
-CFLAGS=-g -O2 -Wall -Wextra -Isrc -rdynamic -DNDEBUG $(OPTFLAGS)
-LIBS=-ldl $(OPTLIBS)
+CFLAGS=-g -O2 -Wall -Wextra -Isrc $(shell pkg-config --cflags libbsd) -rdynamic -DNDEBUG $(OPTFLAGS)
+COMMON_LIBS = $(shell pkg-config --libs libbsd) -ldl $(OPTLIBS)
+LDLIBS=$(COMMON_LIBS)
 PREFIX?=/usr/local

 SOURCES=$(wildcard src/**/*.c src/*.c)
@@ -14,7 +15,7 @@
 # The Target Build
 all: $(TARGET) $(SO_TARGET) tests

-dev: CFLAGS=-g -Wall -Isrc -Wall -Wextra $(OPTFLAGS)
+dev: CFLAGS=-g -Wall -Wextra -Isrc $(shell pkg-config --cflags libbsd) $(OPTFLAGS)
 dev: all

 $(TARGET): CFLAGS += -fPIC
@@ -31,7 +32,7 @@

 # The Unit Tests
 .PHONY: tests
-tests: CFLAGS += $(TARGET)
+tests: LDLIBS = $(TARGET) $(COMMON_LIBS)
 tests: $(TESTS)
    sh ./tests/runtests.sh
于 2013-11-15T09:14:01.330 回答