|
From: | Marco Vassallo |
Subject: | registration of new class |
Date: | Sat, 20 Jul 2013 00:09:44 +0200 |
Hi all,
I have some questions about the registration process for a class derived from octave_base_value. My model is the class myobject which was used in a presentation of c. and Jordi. [1] What I've done is as follow: 1) I want to separate each DLD function in a different file, and let in the file myobject.cc only the implementation of the method of the class. I thus have three new files: myobject_init.cc myobject_get_string.cc myobject_set_str.cc If now I compile the new files, I have to link them against the file myobject.o because the methods of the class are defined here. This produces the following error: "address@hidden:~/devel_fem-fen$ mkoctfile -s myobject_get_str.o myobject.o -o myobject_get_str.oct -I. myobject.o:(.data+0x0): multiple definition of `myobject::t_id' myobject_get_str.o:(.data+0x0): first defined here myobject.o: In function `__exchange_and_add_dispatch': /usr/include/c++/4.7/ostream:528: multiple definition of `myobject::c_name' myobject_get_str.o:/usr/include/c++/4.7/ostream:528: first defined here myobject.o: In function `__exchange_and_add_dispatch': /usr/include/c++/4.7/ostream:531: multiple definition of `myobject::t_name' myobject_get_str.o:/usr/include/c++/4.7/ostream:531: first defined here myobject.o: In function `__static_initialization_and_destruction_0': /home/marco/devel_fem-fen/./myobject.h:64: multiple definition of `myobject::register_type()' myobject_get_str.o:/home/marco/devel_fem-fen/./myobject.h:64: first defined here collect2: error: ld returned 1 exit status" 2) I think that the problem is related to the fact that both files include myobject.h, where we have the following definition twice: DEFINE_OCTAVE_ALLOCATOR (myobject); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject, "myobject", "myobject"); I have thus move these lines to the myobject.cc file and now it compile without any problem. 3) Now my problem is that, when I register my type for the first time, I don't know how I can "dispatch" the information to the other functions. For example, if I call a = myobject_init ('a',1,1) the myobject type is registered and myobject::static_type_id () is set to 54; if now I call one of the other functions, myobject_get_str (a) the variable myobject::static_type_id () is still set to -1, like if it had never been initializated. Thanks for your help Marco [1] http://inversethought.com/hg/what-is-octave/ |
[Prev in Thread] | Current Thread | [Next in Thread] |