lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 12 June 2012 22:13, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
>> don't actually have an OSX platform to test on so I don't know how
>> well/if it works yet.
>
> It does not work for me (Lion):
>
> $ make
> g++ -O2 -Werror -Wall -MD -Isrc -c -o  objs/tuna.o src/tuna.cpp
> src/tuna.cpp:27: error: thread-local storage not supported for this target
>
> Do I have to do something special to compile under OSX?

I have managed to get the 'tuna.so' module compiled on Mac OS X. I had
to change the compiler to clang++, add a -pthread flag and
remove/rename mmap constants to match the Mac API [1]. Note that I did
not test it yet, I am trying to get the examples compiled too...

[1] https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man2/mmap.2.html

Here is a diff of what I had to do to get it compiled (this would have
to be adapted to suit both Linux and Mac):

diff -ur tuna-0.4.3/Makefile tuna-mac/Makefile
--- tuna-0.4.3/Makefile	2012-06-12 14:26:44.000000000 +0200
+++ tuna-mac/Makefile	2012-06-12 22:37:14.000000000 +0200
@@ -4,8 +4,8 @@

 OPT = -O2

-CC = g++ $(OPT) -Werror -Wall -MD -Isrc -c -o
-LCC = g++ -fpic $(OPT) -Werror -Wall -MD -Isrc -c -o
+CC = clang++ $(OPT) -Werror -Wall -MD -Isrc -c -pthread -o
+LCC = clang++ -fpic $(OPT) -Werror -Wall -MD -Isrc -c -pthread -o

 #LIBTOOL=libtool --tag=CXX

@@ -24,7 +24,7 @@
 	@touch Makefile_deps.m

 tuna.so: $(LOBJS)
-	g++ -shared -Wl,-soname,libtuna.so.1 -o tuna.so -lc $(LOBJS) $(LIBS)
+	g++ -bundle -undefined dynamic_lookup -o tuna.so -lc $(LOBJS) $(LIBS)
 	@cp tuna.so examples
 	@find . -name "*.d" -exec mv {} deps \; 2>/dev/null
 	
diff -ur tuna-0.4.3/src/linux_drv.cpp tuna-mac/src/linux_drv.cpp
--- tuna-0.4.3/src/linux_drv.cpp	2012-06-12 14:26:46.000000000 +0200
+++ tuna-mac/src/linux_drv.cpp	2012-06-12 22:34:24.000000000 +0200
@@ -6,7 +6,12 @@
 #include <sys/time.h>
 #include <pthread.h>
 #include <sys/mman.h>
-#include <malloc.h>
+//#include <malloc.h>
+#include <sys/mman.h>
+#ifndef MAP_ANONYMOUS
+# define MAP_ANONYMOUS MAP_ANON
+#endif
+
 #include <errno.h>

 namespace Tuna
@@ -61,7 +66,7 @@
 {
 	MLockScoped m(s_mmaplock);
 	// grab some memory suitable for use as a stack
-	char *ret = (char *)mmap( 0, minSize + sizeof(int),
PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_STACK|MAP_PRIVATE, -1, 0 );
+	char *ret = (char *)mmap( 0, minSize + sizeof(int),
PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0 );
 	// embed the alloc size and shift the returned pointer forward sizoef(int)
 	*(int*)ret = minSize + sizeof(int); // embed the size
 	return ret + sizeof(int);