Hello everyone,
I make a multi-client server in C++ on Linux with sockets using
pthreads. I have noticed that my program doesn't have the same behavior
whether I use my Makefile or not.
My program runs fine when I type "make run" (the binary is executed
through the Makefile, see the attached file). When I run it by hand or
using gdb (or with python popen4) the thread which manage the new
connections (accept() on the main thread socket) cannot accept them
(accept() returns -1 with errno to "Invalid argument"). I tried to put
the thread code in the main and it worked whether I was using gmake or
not.
So my conclusion is that gmake/my Makefile affects the program execution
via permissions of the thread socket/ressource sharing or something like
this. It maybe something else but I wasn't able to reproduce it anywhere
but with gmake. I'm lost in an unknown land and looking for some help.
Can any one give me a hand on this unexcepted behavior ? Many thanks in
advance.
Axel ANGEL.
SRCDIR=src
HEADDIR=include
BUILDDIR=build
DEBUGDIR=$(BUILDDIR)/debug
TEXTUREDIR=textures
OBJFILEDIR=obj
BACKUPDIR=backup
TESTDIR=unittest
TESTFLAGS= $(FLAGS) -lboost_unit_test_framework
CC=g++
FLAGS=-Wall -g -DDEBUG -Wno-write-strings
FLAGS-FINAL=$(FLAGS)
CFLAGS = -L/usr/X11R6/lib -L/usr/local/lib -lm -lrt -lpthread -I$(HEADDIR)
LDFLAGS = $(CFLAGS)
SRC= $(shell find $(SRCDIR) -name "*.cpp")
OBJ= $(SRC:$(SRCDIR)/%.cpp=$(BUILDDIR)/%.o)
EXEC=main
.PHONY: all
all: build
#link all .o to an executable file in debug dir
$(EXEC): $(OBJ)
@if test ! -d "$(DEBUGDIR)"; then mkdir $(DEBUGDIR); fi
$(CC) -o $(DEBUGDIR)/$@ $^ $(LDFLAGS)
@if test -d "$(OBJFILEDIR)"; then cp -Rf $(OBJFILEDIR) $(DEBUGDIR); fi
@if test -d "$(TEXTUREDIR)"; then cp -Rf $(TEXTUREDIR) $(DEBUGDIR); fi
#compile all .cpp and .hpp into .o in build dir
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp $(HEADDIR)/%.hpp
@if test ! -d "$(BUILDDIR)"; then mkdir $(BUILDDIR); fi
$(CC) -o $@ -c $< $(FLAGS) $(CFLAGS)
#clean the build
.PHONY: clean
clean:
@rm -rf $(BUILDDIR) && echo "clean done..."
.PHONY: backup
backup:
@if test ! -d $(BACKUPDIR); then mkdir $(BACKUPDIR); fi
@export temp="$(BACKUPDIR)/$(SRCDIR)-`date`"; mkdir "$${temp}"; cp -R $(SRCDIR) "$${temp}"/$(SRCDIR); cp -R $(HEADDIR) "$${temp}"/$(HEADDIR)
.PHONY: clean-backup
clean-backup:
@rm -rf $(BACKUPDIR)
.PHONY: clean-build
clean-build: clean build
.PHONY: build
build: makesubdir $(EXEC)
makesubdir:
@if test ! -d "$(BUILDDIR)"; then mkdir -p $(BUILDDIR); fi
@if test ! -d "$(DEBUGDIR)"; then mkdir -p $(DEBUGDIR); fi
@cd $(SRCDIR); find -maxdepth 1 -type d -not -wholename "./.*" -exec mkdir -p "../$(BUILDDIR)/{}" \; ;
.PHONY: run
run: build
@cd $(DEBUGDIR); ./$(EXEC)
debugrun: build
@cd $(DEBUGDIR); gdb ./$(EXEC)
test:
$(CC) $(TESTFLAGS) $(TESTDIR)/tests.cpp $(SRCDIR)/charutils.cpp $(SRCDIR)/linkedlist.cpp $(SRCDIR)/linkedlistbi.cpp $(SRCDIR)/linkedhashtable.cpp $(SRCDIR)/hash.cpp -o $(TESTDIR)/main -I$(HEADDIR)
@cd $(TESTDIR); ./main
_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make