fixed errors and warnings when building as C++ - fixes #1

This commit is contained in:
Gregory Pakosz 2015-12-28 16:19:52 +01:00
parent 946b114876
commit d0fc4161e8
4 changed files with 19 additions and 9 deletions

View File

@ -30,7 +30,7 @@ buildir := $(realpath .)/build
binsubdir := $(platform)-$(architecture) binsubdir := $(platform)-$(architecture)
bindir := $(prefix)/bin/$(binsubdir) bindir := $(prefix)/bin/$(binsubdir)
CFLAGS := -O2 -g CFLAGS := -O2 -g -Wall -pedantic -Werror
ifeq ($(platform),linux) ifeq ($(platform),linux)
override LDFLAGS := $(LDFLAGS) -ldl override LDFLAGS := $(LDFLAGS) -ldl
@ -44,22 +44,32 @@ endif
.PHONY: build-executable .PHONY: build-executable
build: 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 $(bindir)/executable: $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/executable.c
mkdir -p $(@D) mkdir -p $(@D)
$(CC) -o $@ -I $(srcdir) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fpic $(filter-out %.h,$^) $(CC) -o $@ -I $(srcdir) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fpic $(filter-out %.h,$^)
$(if $(postbuild),$(postbuild) $@) $(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 .PHONY: build-library
build: 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 $(bindir)/library$(libsuffix): $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/library.c
mkdir -p $(@D) mkdir -p $(@D)
$(CC) -shared -o $@ -I $(srcdir) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fpic $(filter-out %.h,$^) $(CC) -shared -o $@ -I $(srcdir) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fpic $(filter-out %.h,$^)
$(if $(postbuild),$(postbuild) $@) $(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: clean:
rm -rf $(buildir) rm -rf $(buildir)
rm -rf $(bindir) rm -rf $(bindir)

View File

@ -76,7 +76,7 @@ int main(int argc, char** argv)
length = wai_getExecutablePath(NULL, 0, &dirname_length); length = wai_getExecutablePath(NULL, 0, &dirname_length);
if (length > 0) if (length > 0)
{ {
path = malloc(length + 1); path = (char*)malloc(length + 1);
wai_getExecutablePath(path, length, &dirname_length); wai_getExecutablePath(path, length, &dirname_length);
path[length] = '\0'; path[length] = '\0';
@ -90,7 +90,7 @@ int main(int argc, char** argv)
length = wai_getModulePath(NULL, 0, &dirname_length); length = wai_getModulePath(NULL, 0, &dirname_length);
if (length > 0) if (length > 0)
{ {
path = malloc(length + 1); path = (char*)malloc(length + 1);
wai_getModulePath(path, length, &dirname_length); wai_getModulePath(path, length, &dirname_length);
path[length] = '\0'; path[length] = '\0';

View File

@ -16,7 +16,7 @@ static void load()
length = wai_getExecutablePath(NULL, 0, &dirname_length); length = wai_getExecutablePath(NULL, 0, &dirname_length);
if (length > 0) if (length > 0)
{ {
path = malloc(length + 1); path = (char*)malloc(length + 1);
wai_getExecutablePath(path, length, &dirname_length); wai_getExecutablePath(path, length, &dirname_length);
path[length] = '\0'; path[length] = '\0';
@ -30,7 +30,7 @@ static void load()
length = wai_getModulePath(NULL, 0, &dirname_length); length = wai_getModulePath(NULL, 0, &dirname_length);
if (length > 0) if (length > 0)
{ {
path = malloc(length + 1); path = (char*)malloc(length + 1);
wai_getModulePath(path, length, &dirname_length); wai_getModulePath(path, length, &dirname_length);
path[length] = '\0'; path[length] = '\0';

View File

@ -258,7 +258,7 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
char* begin; char* begin;
char* p; 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; p = begin + offset;
while (p >= begin) // scan backwards 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)); 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);
memcpy(&buffer[length + 2], p + 30, length_); memcpy(&buffer[length + 2], p + 30, length_);