On 12/20/2010 04:37 PM, John Cummings wrote:
> On 12/17/2010 05:05 PM, Hugo Parente Lima wrote:
>   
>>> With that change, everything  compiles fine. However,  when trying to
>>>       
>>>> run the python test script, it fails with an error about an undefined
>>>> symbol that said, "ImportError: .../foo.so: undefined symbol:
>>>> _Z8init_barP7_object."
>>>>
>>>> I then went through several failed attempts to compile in the new
>>>> bar_wrapper.cpp that the generator also created. As I said, none of
>>>> those worked, so I eventually tried again by redoing foo.h as follows:
>>>>         
>>>     
>>>       
>> Why you can't compile bar_wrapper.cpp!? What errors happened?
>>
>>   
>>     
>>>> namespace bar {
>>>>    class Math;
>>>> }
>>>> class bar::Math : public QObject
>>>> {
>>>>     Q_OBJECT
>>>> public:
>>>>     Math() {}
>>>>     virtual ~Math() {}
>>>>     int squared(int x);
>>>> };
>>>>
>>>> With this change along with prefixing the class with "bar::" in the
>>>> typesystem.xml file and the resulting file names changes in the
>>>> CMakeLists.txt file, everything works as you would expect.
>>>>
>>>> So, that leads me to my questions again. Why does it work with the
>>>> forward declaration syntax but not the inline syntax? My best guess
>>>> would be a generator parser limitation based on the warning message.
>>>> However, I have not attempted to delve into the code at all.
>>>>         
>>>     
>>>       
>> We need to known the problems you had trying to compile bar_wrapper.cpp, 
>> because libfoo uses inline namespaces and works.
>>
>>   
>>     
> First, thank you for your quick answer.
>
> I then need to offer my apologies. I cannot reproduce this particular
> error in the libfoo example. I believe that I may have confused work on
> my existing library with the test case because I cannot recreate this
> issue in the smaller testing environment. I am checking into it.
>
>   

It appears that in fact I may have been confusing the simple libfoo
example and my more complex existing library. However, I can now cause
compilation to fail once again.

To cause a failure, I overloaded the "==" operator for the Math type in
foo.h:

namespace bar {
class Math : public QObject
{
...
};
bool operator == (const Math& left, const Math& right);
}

Then in foo.cpp we have:

bool bar::operator ==(const bar::Math& left, const bar::Math& right)
{
return &left == &right;
}

I can compile libfoo just fine, generate bindings, etc.. However, trying
to compile bar_wrapper.cpp fails with the following errors:

/tmp/binding-tutorial/foobinding-cmake/build/foo/foo/bar_wrapper.cpp: In
function ‘PyObject* Sbk_bar_richcompare(PyObject*, PyObject*, int)’:
/tmp/binding-tutorial/foobinding-cmake/build/foo/foo/bar_wrapper.cpp:31:8:
error: expected primary-expression before ‘&’ token
/tmp/binding-tutorial/foobinding-cmake/build/foo/foo/bar_wrapper.cpp:31:10:
error: ‘cppSelf’ was not declared in this scope
/tmp/binding-tutorial/foobinding-cmake/build/foo/foo/bar_wrapper.cpp:31:21:
error: expected primary-expression before ‘;’ token
/tmp/binding-tutorial/foobinding-cmake/build/foo/foo/bar_wrapper.cpp:35:2:
error: expected primary-expression before ‘else’
/tmp/binding-tutorial/foobinding-cmake/build/foo/foo/bar_wrapper.cpp:35:2:
error: expected ‘;’ before ‘else’
/tmp/binding-tutorial/foobinding-cmake/build/foo/foo/bar_wrapper.cpp:45:5:
warning: label ‘Sbk_bar_RichComparison_TypeError’ defined but not used

I see a vague reference to operators in the documentation:

http://www.pyside.org/docs/apiextractor/typesystem_specifying_types.html#object-type

I tried setting the stream parameter to yes or no and that does not seem
to make a difference. However, you already indicated that the
documentation may be out of date.

So, is there another setting I am missing?

I am attaching a patch file for the Binding Tutorial example tarball
that is found here:

http://pyside.org/files/binding-tutorial.tar.gz

The patch modifies libfoo and foobindings-cmake files.

Thank you
John Cummings

=== modified file 'foobinding-cmake/foo/CMakeLists.txt'
--- foobinding-cmake/foo/CMakeLists.txt	2010-12-17 15:31:58 +0000
+++ foobinding-cmake/foo/CMakeLists.txt	2010-12-20 23:32:00 +0000
@@ -1,8 +1,10 @@
 project(foo)
 
+
 set(foo_SRC
     ${CMAKE_CURRENT_BINARY_DIR}/foo/foo_module_wrapper.cpp
-    ${CMAKE_CURRENT_BINARY_DIR}/foo/math_wrapper.cpp
+    ${CMAKE_CURRENT_BINARY_DIR}/foo/bar_wrapper.cpp
+    ${CMAKE_CURRENT_BINARY_DIR}/foo/bar_math_wrapper.cpp
 )
 
 set(foo_INCLUDE_DIRECTORIES

=== modified file 'foobinding-cmake/foo/typesystem_foo.xml'
--- foobinding-cmake/foo/typesystem_foo.xml	2010-12-17 15:31:58 +0000
+++ foobinding-cmake/foo/typesystem_foo.xml	2010-12-20 23:46:36 +0000
@@ -1,6 +1,8 @@
 <?xml version="1.0"?>
 <typesystem package="foo">
     <load-typesystem name="typesystem_core.xml" generate="no" />
-    <object-type name="Math" />
+    <namespace-type name="bar">
+       <object-type name="Math"  stream="no" />
+    </namespace-type>
 </typesystem>
 

=== modified file 'foobinding-cmake/tests/math_test.py'
--- foobinding-cmake/tests/math_test.py	2010-12-17 15:31:58 +0000
+++ foobinding-cmake/tests/math_test.py	2010-12-20 23:32:00 +0000
@@ -11,7 +11,7 @@
     def testMath(self):
         '''Test case for Math class from foo module.'''
         val = 5
-        math = foo.Math()
+        math = foo.bar.Math()
         self.assertEqual(math.squared(5), 5 * 5)
 
 if __name__ == '__main__':

=== modified file 'libfoo/foo.cpp'
--- libfoo/foo.cpp	2010-12-17 15:31:58 +0000
+++ libfoo/foo.cpp	2010-12-20 23:32:00 +0000
@@ -1,7 +1,11 @@
 #include "foo.h"
 
-int Math::squared(int x)
+int bar::Math::squared(int x)
 {
     return x * x;
 }
 
+bool bar::operator ==(const bar::Math& left, const bar::Math& right)
+{
+   return &left == &right;
+}

=== modified file 'libfoo/foo.h'
--- libfoo/foo.h	2010-12-17 15:31:58 +0000
+++ libfoo/foo.h	2010-12-20 23:32:00 +0000
@@ -3,6 +3,7 @@
 
 #include <QtCore/QtCore>
 
+namespace bar {
 class Math : public QObject
 {
     Q_OBJECT
@@ -11,6 +12,9 @@
     virtual ~Math() {}
     int squared(int x);
 };
+bool operator == (const Math& left, const Math& right);
+}
+
 
 #endif // FOO_H
 

_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside

Reply via email to