From d0fc4161e84465eaecd86121fbb7565503e8447c Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Mon, 28 Dec 2015 16:19:52 +0100 Subject: [PATCH] fixed errors and warnings when building as C++ - fixes #1 --- _gnu-make/Makefile | 16 +++++++++++++--- example/executable.c | 4 ++-- example/library.c | 4 ++-- src/whereami.c | 4 ++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/_gnu-make/Makefile b/_gnu-make/Makefile index 06fa115..fe32c26 100644 --- a/_gnu-make/Makefile +++ b/_gnu-make/Makefile @@ -30,7 +30,7 @@ buildir := $(realpath .)/build binsubdir := $(platform)-$(architecture) bindir := $(prefix)/bin/$(binsubdir) -CFLAGS := -O2 -g +CFLAGS := -O2 -g -Wall -pedantic -Werror ifeq ($(platform),linux) override LDFLAGS := $(LDFLAGS) -ldl @@ -44,22 +44,32 @@ endif .PHONY: build-executable build: build-executable -build-executable: $(bindir)/executable +build-executable: $(bindir)/executable $(bindir)/executable-cpp $(bindir)/executable: $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/executable.c mkdir -p $(@D) $(CC) -o $@ -I $(srcdir) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fpic $(filter-out %.h,$^) $(if $(postbuild),$(postbuild) $@) +$(bindir)/executable-cpp: $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/executable.c + mkdir -p $(@D) + $(CC) -x c++ -o $@ -I $(srcdir) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fpic $(filter-out %.h,$^) + $(if $(postbuild),$(postbuild) $@) + .PHONY: build-library build: build-library -build-library: $(bindir)/library$(libsuffix) +build-library: $(bindir)/library$(libsuffix) $(bindir)/library-cpp$(libsuffix) $(bindir)/library$(libsuffix): $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/library.c mkdir -p $(@D) $(CC) -shared -o $@ -I $(srcdir) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fpic $(filter-out %.h,$^) $(if $(postbuild),$(postbuild) $@) +$(bindir)/library-cpp$(libsuffix): $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/library.c + mkdir -p $(@D) + $(CC) -x c++ -shared -o $@ -I $(srcdir) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fpic $(filter-out %.h,$^) + $(if $(postbuild),$(postbuild) $@) + clean: rm -rf $(buildir) rm -rf $(bindir) diff --git a/example/executable.c b/example/executable.c index afa39a3..b23da0b 100644 --- a/example/executable.c +++ b/example/executable.c @@ -76,7 +76,7 @@ int main(int argc, char** argv) length = wai_getExecutablePath(NULL, 0, &dirname_length); if (length > 0) { - path = malloc(length + 1); + path = (char*)malloc(length + 1); wai_getExecutablePath(path, length, &dirname_length); path[length] = '\0'; @@ -90,7 +90,7 @@ int main(int argc, char** argv) length = wai_getModulePath(NULL, 0, &dirname_length); if (length > 0) { - path = malloc(length + 1); + path = (char*)malloc(length + 1); wai_getModulePath(path, length, &dirname_length); path[length] = '\0'; diff --git a/example/library.c b/example/library.c index b07e876..dec6c12 100644 --- a/example/library.c +++ b/example/library.c @@ -16,7 +16,7 @@ static void load() length = wai_getExecutablePath(NULL, 0, &dirname_length); if (length > 0) { - path = malloc(length + 1); + path = (char*)malloc(length + 1); wai_getExecutablePath(path, length, &dirname_length); path[length] = '\0'; @@ -30,7 +30,7 @@ static void load() length = wai_getModulePath(NULL, 0, &dirname_length); if (length > 0) { - path = malloc(length + 1); + path = (char*)malloc(length + 1); wai_getModulePath(path, length, &dirname_length); path[length] = '\0'; diff --git a/src/whereami.c b/src/whereami.c index e969270..971c740 100644 --- a/src/whereami.c +++ b/src/whereami.c @@ -258,7 +258,7 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) char* begin; char* p; - begin = mmap(0, offset, PROT_READ, MAP_SHARED, fd, 0); + begin = (char*)mmap(0, offset, PROT_READ, MAP_SHARED, fd, 0); p = begin + offset; while (p >= begin) // scan backwards @@ -267,7 +267,7 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) { uint16_t length_ = *((uint16_t*)(p + 26)); - if (length + 2 + length_ < sizeof(buffer)) + if (length + 2 + length_ < (int)sizeof(buffer)) { memcpy(&buffer[length], "!/", 2); memcpy(&buffer[length + 2], p + 30, length_);