[Olsr-dev] Makefiles patch for pthreads

Gianni Costanzi (spam-protected)
Thu Aug 23 12:28:00 CEST 2007


Hi,
I'm working on an olsrd plugin that uses pthreads and I've spent last
days dealing with some strange segmentation faults and other problems
when running olsrd on my ARMEB APs.. All my problems were related to
libpthread, which I did not specify in the Makefile when olsrd
executable is linked..
BTW, I've specified it but I've also made some modifications to
Makefile, Makefile.inc and make/Makefile.linux, since there were the
following "problems" in my opinion:

- -O2 and -g should not be specified together.. when you debug you do
not usually want optimized code (I've specified -ggdb in the following
diff output, you can replace with -g if you don't use gdb)

- -pthread should be specified to gcc along with -lpthread, since this
last one links the libpthread library and -pthread does some other
work:
"GCC MAN PAGE--> -pthread   Add support for multithreading using the
POSIX threads library.  This option sets flags for both the
preprocessor and linker.  This option does not affect the thread
safety of object code produced  by the compiler or that of libraries
supplied with it."

- libraries should be specified before the source files.
- $(CFLAGS) is missing when compiling/linking olsrd

So, these are the modifications that I've made to the makefiles:
diff -ur --exclude=.svn 0.5.3/make/Makefile.linux new/make/Makefile.linux
--- 0.5.3/make/Makefile.linux   2007-08-23 12:05:40.000000000 +0200
+++ new/make/Makefile.linux     2007-08-23 12:04:48.000000000 +0200
@@ -29,6 +29,7 @@
 endif

 OS_LIB_PTHREAD = -lpthread
+OS_CFLAG_PTHREAD = -pthread
 OS_LIB_DYNLOAD = -ldl

 # Local Variables:
diff -ur --exclude=.svn 0.5.3/Makefile new/Makefile
--- 0.5.3/Makefile      2007-08-23 12:05:27.000000000 +0200
+++ new/Makefile        2007-08-23 12:07:29.000000000 +0200
@@ -48,7 +48,7 @@

 MAKECMD = $(MAKE) OS="$(OS)" WARNINGS="$(WARNINGS)"

-LIBS +=                $(OS_LIB_DYNLOAD)
+LIBS +=                $(OS_LIB_DYNLOAD) $(OS_LIB_PTHREAD)

 ifeq ($(OS), win32)
 LDFLAGS +=     -Wl,--out-implib=libolsrd.a -Wl,--export-all-symbols
@@ -63,7 +63,7 @@
 default_target: cfgparser olsrd

 olsrd:         $(OBJS) $(CFGOBJS)
-               $(CC) $(LDFLAGS) -o $@ $(OBJS) $(CFGOBJS) $(LIBS)
+               $(CC) $(LDFLAGS) $(CFLAGS) $(LIBS) -o $@ $(OBJS) $(CFGOBJS)

 cfgparser:     $(CFGDEPS)
                $(MAKECMD) -C $(CFGDIR)
diff -ur --exclude=.svn 0.5.3/Makefile.inc new/Makefile.inc
--- 0.5.3/Makefile.inc  2007-08-23 12:05:27.000000000 +0200
+++ new/Makefile.inc    2007-08-23 12:09:38.000000000 +0200
@@ -47,8 +47,13 @@
 WARNINGS :=    $(shell CC="$(CC)" $(TOPDIR)/gcc-warnings $(WARNINGS))
 endif
 CFLAGS +=      $(WARNINGS)
-CFLAGS +=      -O2
-CFLAGS +=      -g
+
+CFLAGS += -ggdb
+# -O2 should not be specified when using -ggdb
+#CFLAGS += -O2
+
+# Must be specified along with -lpthread on linux
+CFLAGS += $(OS_CFLAG_PTHREAD)
 endif

 ifdef OLSRD_PLUGIN


Let me know your opinion..
Gianni

-- 
--------------------------------------------------------------------------------------------------------------
|  Gianni Costanzi ((spam-protected))
|       (http://utenti.lycos.it/giannicostanzi/)
|
|  Gentoo Documentation Project (GDP) Member - Italian Translator
|       (http://www.gentoo.org/proj/en/gdp/)
|
|  Free Software Foundation Member #3844 (www.fsf.org)
|       "Free Software is a matter of Liberty not price"
|
|  Sun Valley in Rock Staff Member (www.sunvalleyinrock.net/forum)
--------------------------------------------------------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefiles_pthread.patch
Type: application/octet-stream
Size: 1498 bytes
Desc: not available
URL: <http://lists.olsr.org/pipermail/olsr-dev/attachments/20070823/7302510f/attachment.obj>


More information about the Olsr-dev mailing list