luabind xcode universal static library!

I finally got it to work to make a fat static library for luabind that works on ppc and intel mac but I am experiencing some really weird errors when usind it with OF. If I include #include <luabind/luabind.hpp> in the testApp.h where you would usually put it in it throws some weird template errors (38 of those):

luabind/luabind/class.hpp:1029: error: expected identifier before numeric constant
luabind/luabind/class.hpp:1029: error: expected `>’ before numeric constant
luabind/luabind/class.hpp:1030: error: ‘B1’ was not declared in this scope
luabind/luabind/class.hpp:1030: error: ‘B2’ was not declared in this scope
luabind/luabind/class.hpp:1030: error: ‘B3’ was not declared in this scope
luabind/luabind/class.hpp:1030: error: type/value mismatch at argument 1 in template parameter list for ‘template<class A0, class A1, class A2, class A3> struct luabind::bases’
luabind/luabind/class.hpp:1030: error: expected a type, got ‘0’
luabind/luabind/class.hpp:1030: error: template argument 2 is invalid
luabind/luabind/class.hpp:1030: error: template argument 3 is invalid
luabind/luabind/class.hpp:1030: error: template argument 4 is invalid
luabind/luabind/class.hpp:1030: error: template argument 1 is invalid
luabind/luabind/class.hpp:1032: error: type/value mismatch at argument 1 in template parameter list for ‘template struct luabind::detail::type_’
luabind/luabind/class.hpp:1032: error: expected a type, got ‘0’
luabind/luabind/class.hpp:1032: error: ‘B1’ was not declared in this scope
luabind/luabind/class.hpp:1032: error: template argument 1 is invalid
luabind/luabind/class.hpp:1032: error: ‘B2’ was not declared in this scope
luabind/luabind/class.hpp:1032: error: template argument 1 is invalid
luabind/luabind/class.hpp:1032: error: ‘B3’ was not declared in this scope
luabind/luabind/class.hpp:1032: error: template argument 1 is invalid

the weird thing is, if I include it in the testApp.cpp before I include testApp.h eversthing works fine, only if I include it within testApp.h or after testApp.h those errors ocur. Any ideas what could cause that?

Thanks!

it could be some conflicting data types

for example when PI is defined by OF and by another library.

if you could paste what lines those errors are referring to it will help in debugging the problem.

Theo

it refers to these lines:

  
  
#define LUABIND_GEN_BASE_INFO(z, n, text) gen_base_info(detail::type_<B##n>());  
  
		template<BOOST_PP_ENUM_PARAMS(LUABIND_MAX_BASES, class B)>  
		void generate_baseclass_list(detail::type_<bases<BOOST_PP_ENUM_PARAMS(LUABIND_MAX_BASES, B)> >)  
		{  
			BOOST_PP_REPEAT(LUABIND_MAX_BASES, LUABIND_GEN_BASE_INFO, _)  
		}  
  
#undef LUABIND_GEN_BASE_INFO  
  

another thing I didi in luabind.hpp was to undef these things (I think they conflict with some defaul xcode macros)

  
#ifndef LUABIND_BIND_HPP_INCLUDED  
#define LUABIND_BIND_HPP_INCLUDED  
  
//this is added by me  
#ifdef check  
#undef check  
#endif  
  
#ifdef nil  
#undef nil  
#endif  
//end  
  
#include <luabind/config.hpp>  
#include <luabind/class.hpp>  
#include <luabind/function.hpp>  
#include <luabind/open.hpp>  
  
#endif // LUABIND_BIND_HPP_INCLUDED  
  

It would be awesome to get it to work completely :slight_smile:

do you think you could post an example that reproduces those errors - they look like some strange template errors indeed.

I have to confess I have never seen B##n before!

Theo

B##n is a macro construct that chains B to the content of n.
so if you call LUABIND_GEN_BASE_INFO(z, n, text) with n = labla
then B##n will expand to Blabla.

best
joerg

yes, thats just some boost preprocessor stuff, where function templates get generated. I still don’t get how this can cause errors if I include it in testApp.h, but wors fine if I include it in testApp.cpp before testApp.h.

I tried the same thing in ubuntu today and its the same problem, so its not mac specific but somehow a general problem with luabind and of. the workaround (including luabind at the beginning of testApp.cpp) works, so its no big deal, but kind of ugly :slight_smile:

does anybody have an idea about to fix it? I am currently trying to build a small framework around luabind and its kind of like a pain to do that if I cant include luabind in testApp.h (since I also cant include any files there that use luabind.hpp) so weird…

usually when very strange things happen it’s because of headers that get included twice. make sure you don’t.
can you post testApp.h and testApp.cpp? otherwise it’s just guessing.

best
joerg

thats definately not the case, I allready narrowed the problem down to these three files included in ofMain (not a 100% sure but almost):

  
  
#ifndef TARGET_OF_IPHONE  
	#include "ofSerial.h"  
	#include "ofStandardFirmata.h"  
	#include "ofArduino.h"  
#endif  
  

something in it conflicts with luabind and breaks it. maybe some macros, i need to check that out a little more.

edit: now I am 100% sure that it its one of those three. since they all use ofserial the catch is propably in there.

i think there’s a way to view the output of the preprocessor. there’s ought to be some compiler flag so that it outputs the code after the preprocessor only.

best
joerg

that would make it alot easier. I am on ubuntu in codeblocks right now so if anybody know how to do that there it would be awesome :slight_smile:

how about “man gcc” on the console?

best
joerg

how would you do that? i have actually no clue about codeblocks and I am just getting started with it.

I am sure now that the problem is the #include <termios.h> include in ofSerial.h, since everything compiles without it. an optimal way would be to uninclude after ofSerial but I guess thats not possible…any ideas on that?

a simple workaround would be to include all the files related to ofSerial manually after the luabind stuff and delete the inclusion from ofMain.h thats what I do right now. Would be awesome though to get it fixed so i could maybe release the stuff I am working on as an easy to use addon.

i don’t know anything about codeblocks, the only advice i can give is to look in the manual pages of gcc (the c-compiler are using most likely). to do that open a terminal window in linux and type man gcc. then look for the compiler switch. there should be a way to add that to your settings in codeblocks but i don’t know how.
but maybe it’s too much. there should be an easier way to solve your problem but without the full code it’s no use trying to solve it-

best
joerg

I’m trying to build lua+luabind in OF and getting similar problems with the check and nil macro defines.

From reading this (http://boost-geometry.203548.n3.nabble.com/problems-with-Boost-Geometry-Xcode-compile-td437866.html), I found you can disable the old macro names in AssertMacros.h by setting __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0 in the C flags. This gets lua to build fine but luabind still fails on: ‘Macro “check” passed 2 arguments, but takes just 1’, even when I use the undef hack.

As a control, I made a non-OF test project and lua+luabind build and work fine, no problems.

Any ideas? I’m banging my head against the wall. I can put up the code+project later today … (ofxLua)

Ok, I managed to get everything to build.

Some notes:

  • I needed to add -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0 to *both* the C flags and CPP flags. It seems the define was not being set for the luabind C++ sources when compiling, so the check macro from AssertHeaders.h was still being set, annoying.

  • Now that the check macro conflicts were gone, I had conflicts from the nil macro in MacTypes.h. Again, the undef hack doesn’t seem to work. I then decided to spilt the lua and luabind code out of the single target and into 2 static libs.

  • lua builds fine in a static lib but luabind now throws a weird template error. It seems to be a namespaace problem as detailed here (http://osdir.com/ml/lang.lua.bind.user/2007-06/msg00013.html). Adding luabind::detail:: before each ambiguous function call fixed it.

Great, so now I can compile and actually *do* something. Ideally, I’d prefer a single target without the static libs (makes addon usage easier for newbies), but it is working at least.

Luabind is working and ofxLua is live: http://forum.openframeworks.cc/t/ofxlua/6493/0