Hi,

you are running into these problems because I didn't really take care that the 
registry can be extended by users - sorry about that.  I'll put the helper 
functions in a header so you can include them.  The linker problems are due to 
missing export declarations.  You can probably work around that problem by 
compiling Gecode with the --disable-gcc-visibility configure switch.  I'll also 
fix that.

Cheers,
Guido

On 7 May 2012, at 21:58, Jean-Noël Monette wrote:

> Hello,
> 
> I would like to extend the Gecode/Flatzinc interface to handle "natively" 
> more constraints (that I implemented in Gecode). The way I do it is to add 
> new constraints to the Registry global object. So my code looks like:
> 
> #include <gecode/flatzinc.hh>
> #include <gecode/flatzinc/registry.hh>
> #include "my_cstr_prop.hh"
> 
> namespace Gecode { namespace FlatZinc {
> 
> void p_my_cstr(FlatZincSpace& s, const ConExpr& ce, AST::Node* ann) {
>      IntVar x = getIntVar(s, ce[0]);
>      IntVar y = getIntVar(s, ce[1]);
>      My_CSTR(s,x,y,ann2icl(ann));
>    }
> 
> class MyPoster {
>   public:
>   MyPoster(void) {
>       registry().add("my_cstr", &p_my_cstr);
>   }
> };
> MyPoster __my_poster;
> }}
> 
> This is done by "monkey-see-monkey-do" from the file registry.cpp. However, I 
> ran into several problems. First, I had to add the definition of "getIntVar" 
> and "ann2icl", that I just copy-pasted from registry.cpp (as they are not 
> declared in a header file, and furthermore are in an anonymous namespace). 
> So, my question is to know if this is the way I'm suppose to do it, or if 
> there is a more straightforward way to extend the Gecode/Flatzinc interface 
> with new constraints.
> 
> 
> Second (this might be more related to c++ rather than Gecode, apologizes if 
> this is indeed the case), I've been unable to link the resulting object file 
> against libgecodeflatzinc.so with the following command (fz.o is the object 
> file from fz.cpp in the gecode distrib):
> 
> g++   ./src_c/fz.o ./src_c/my_cstr.o   -lgecodeflatzinc -lgecodedriver 
> -lgecodesearch -lgecodeminimodel -lgecodeset -lgecodeint -lgecodekernel 
> -lgecodesupport
> 
> It yields the following error:
> 
> ./src_c/my_cstr.o: In function `global constructors keyed to 
> _Z3NEQN6Gecode4HomeENS_6IntVarES1_NS_11IntConLevelE':
> my_cstr.cpp:(.text+0x2667): undefined reference to 
> `Gecode::FlatZinc::registry()'
> my_cstr.cpp:(.text+0x2679): undefined reference to 
> `Gecode::FlatZinc::Registry::add(std::basic_string<char, 
> std::char_traits<char>, std::allocator<char> > const&, void 
> (*)(Gecode::FlatZinc::FlatZincSpace&, Gecode::FlatZinc::ConExpr const&, 
> Gecode::FlatZinc::AST::Node*))'
> 
> However, I'm able to link the same object file against the object files that 
> are compiled into libgecodeflatzinc:
> 
> g++  ./src_c/fz.o ./src_c/my_cstr.o  gecode-3.7.3/gecode/flatzinc/*.o 
> -lgecodedriver -lgecodesearch -lgecodeminimodel -lgecodeset -lgecodeint 
> -lgecodekernel -lgecodesupport
> 
> So, I'm wondering why and how this is happening, and I have no clue... (I'm 
> using Gecode 3.7.1, compiler is gcc 4.5.2, on Ubuntu 11.04)
> 
> Thank you very much for your help,
> 
> Jean-Noël Monette
> 
> 
> _______________________________________________
> Gecode users mailing list
> [email protected]
> https://www.gecode.org/mailman/listinfo/gecode-users

-- 
Guido Tack,
http://www.csse.monash.edu/~guidot/



_______________________________________________
Gecode users mailing list
[email protected]
https://www.gecode.org/mailman/listinfo/gecode-users

Reply via email to