jim-easterbrook / python-gphoto2

Python interface to libgphoto2
GNU Lesser General Public License v3.0
363 stars 59 forks source link

Compile error in (Py_ssize_t)offsetof(SwigPyObject, dict) #4

Closed jim-easterbrook closed 9 years ago

jim-easterbrook commented 10 years ago

If you have SWIG version 2.0.11 ('swig -version' will show you) you may get errors like this:

running build
running build_ext
building '_gphoto2_abilities_list' extension
swigging src/gphoto2/lib/gphoto2_abilities_list.i to src/gphoto2/lib/gphoto2_abilities_list_wrap.c
swig -python -I/usr/include -builtin -O -Wall -DGPHOTO2_25 -o src/gphoto2/lib/gphoto2_abilities_list_wrap.c src/gphoto2/lib/gphoto2_abilities_list.i
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/gphoto2/lib/gphoto2_abilities_list_wrap.c -o build/temp.linux-x86_64-2.7/src/gphoto2/lib/gphoto2_abilities_list_wrap.o -O3 -Wno-unused-variable -DGPHOTO2_25
src/gphoto2/lib/gphoto2_abilities_list_wrap.c:5580:5: warning: implicit declaration of function `offsetof' [-Wimplicit-function-declaration]
     (Py_ssize_t)offsetof(SwigPyObject, dict), /* tp_dictoffset */
     ^
src/gphoto2/lib/gphoto2_abilities_list_wrap.c:5580:26: error: expected expression before `SwigPyObject'
     (Py_ssize_t)offsetof(SwigPyObject, dict), /* tp_dictoffset */

If this happens, edit setup.py and remove '-builtin' from the swig_opts declaration.

codebuk commented 9 years ago

Hi,

On Fedora 20 with swig 2.0.11 I get similar errors. I have added and removed -builtin from swig-opts. Is there anything else I should try?

Dan

 bash-4.2$ python setup.py --verbose build
running build
running build_ext
building '_gphoto2_abilities_list' extension
swigging src/gphoto2/lib/gphoto2_abilities_list.i to src/gphoto2/lib/gphoto2_abilities_list_wrap.c
swig -python -nodefaultctor -O -Wextra -Werror -MMD -DGPHOTO2_25 -I/usr/include -o src/gphoto2/lib/gphoto2_abilities_list_wrap.c src/gphoto2/lib/gphoto2_abilities_list.i
creating build
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/src
creating build/temp.linux-x86_64-2.7/src/gphoto2
creating build/temp.linux-x86_64-2.7/src/gphoto2/lib
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c src/gphoto2/lib/gphoto2_abilities_list_wrap.c -o build/temp.linux-x86_64-2.7/src/gphoto2/lib/gphoto2_abilities_list_wrap.o -O3 -Wno-unused-variable -Wno-strict-prototypes -Werror -DGPHOTO2_25
src/gphoto2/lib/gphoto2_abilities_list_wrap.c: In function ‘_wrap_CameraAbilitiesList___len__’:
src/gphoto2/lib/gphoto2_abilities_list_wrap.c:3398:5: error: implicit declaration of function ‘struct__CameraAbilitiesList___len__’ [-Werror=implicit-function-declaration]
     result = (int)struct__CameraAbilitiesList___len__(arg1);
     ^
src/gphoto2/lib/gphoto2_abilities_list_wrap.c: In function ‘_wrap_CameraAbilitiesList_count’:
src/gphoto2/lib/gphoto2_abilities_list_wrap.c:3694:5: error: implicit declaration of function ‘struct__CameraAbilitiesList_count’ [-Werror=implicit-function-declaration]
     result = (int)struct__CameraAbilitiesList_count(arg1);
     ^
src/gphoto2/lib/gphoto2_abilities_list_wrap.c: In function ‘_wrap_CameraAbilitiesList_lookup_model’:
src/gphoto2/lib/gphoto2_abilities_list_wrap.c:3733:5: error: implicit declaration of function ‘struct__CameraAbilitiesList_lookup_model’ [-Werror=implicit-function-declaration]
     result = (int)struct__CameraAbilitiesList_lookup_model(arg1,(char const *)arg2);
     ^
cc1: all warnings being treated as errors
error: command 'gcc' failed with exit status 1
bash-4.2$ python setup.py --verbose build
running build
running build_ext
building '_gphoto2_abilities_list' extension
swigging src/gphoto2/lib/gphoto2_abilities_list.i to src/gphoto2/lib/gphoto2_abilities_list_wrap.c
swig -python -nodefaultctor -O -Wextra -Werror -MMD -builtin -DGPHOTO2_25 -I/usr/include -o src/gphoto2/lib/gphoto2_abilities_list_wrap.c src/gphoto2/lib/gphoto2_abilities_list.i
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c src/gphoto2/lib/gphoto2_abilities_list_wrap.c -o build/temp.linux-x86_64-2.7/src/gphoto2/lib/gphoto2_abilities_list_wrap.o -O3 -Wno-unused-variable -Wno-strict-prototypes -Werror -DGPHOTO2_25
src/gphoto2/lib/gphoto2_abilities_list_wrap.c: In function ‘_wrap_CameraAbilitiesList___len__’:
src/gphoto2/lib/gphoto2_abilities_list_wrap.c:3913:5: error: implicit declaration of function ‘struct__CameraAbilitiesList___len__’ [-Werror=implicit-function-declaration]
     result = (int)struct__CameraAbilitiesList___len__(arg1);
     ^
src/gphoto2/lib/gphoto2_abilities_list_wrap.c: In function ‘_wrap_CameraAbilitiesList_count’:
src/gphoto2/lib/gphoto2_abilities_list_wrap.c:4214:5: error: implicit declaration of function ‘struct__CameraAbilitiesList_count’ [-Werror=implicit-function-declaration]
     result = (int)struct__CameraAbilitiesList_count(arg1);
     ^
src/gphoto2/lib/gphoto2_abilities_list_wrap.c: In function ‘_wrap_CameraAbilitiesList_lookup_model’:
src/gphoto2/lib/gphoto2_abilities_list_wrap.c:4254:5: error: implicit declaration of function ‘struct__CameraAbilitiesList_lookup_model’ [-Werror=implicit-function-declaration]
     result = (int)struct__CameraAbilitiesList_lookup_model(arg1,(char const *)arg2);
     ^
src/gphoto2/lib/gphoto2_abilities_list_wrap.c: At top level:
src/gphoto2/lib/gphoto2_abilities_list_wrap.c:5479:5: error: implicit declaration of function ‘offsetof’ [-Werror=implicit-function-declaration]
     (Py_ssize_t)offsetof(SwigPyObject, dict), /* tp_dictoffset */
     ^
src/gphoto2/lib/gphoto2_abilities_list_wrap.c:5479:26: error: expected expression before ‘SwigPyObject’
     (Py_ssize_t)offsetof(SwigPyObject, dict), /* tp_dictoffset */
                          ^
src/gphoto2/lib/gphoto2_abilities_list_wrap.c:5731:26: error: expected expression before ‘SwigPyObject’
     (Py_ssize_t)offsetof(SwigPyObject, dict), /* tp_dictoffset */
                          ^
cc1: all warnings being treated as errors
error: command 'gcc' failed with exit status 1
bash-4.2$ 
jim-easterbrook commented 9 years ago

Are you using a version newer than commit 86f261e, and have you tried completely removing the build directory?

codebuk commented 9 years ago

Jim,

Yes. Newer than 86f261e https://github.com/jim-easterbrook/python-gphoto2/commit/86f261edfdf00de5fc74261676ff9b360d13e1ff .

Have deleted build directory.

Dan

Cheers,

Dan Tyrrell Data & Networks Techniek m 0409 964694 e dan@dnt.com.au www.dnt.com.au

On 2 December 2014 at 19:23, Jim Easterbrook notifications@github.com wrote:

Are you using a version newer than commit 86f261e https://github.com/jim-easterbrook/python-gphoto2/commit/86f261edfdf00de5fc74261676ff9b360d13e1ff, and have you tried completely removing the build directory?

— Reply to this email directly or view it on GitHub https://github.com/jim-easterbrook/python-gphoto2/issues/4#issuecomment-65196673 .

jim-easterbrook commented 9 years ago

That's odd, as your log messages show the -builtin option being used. Can you add some "print swig_version" statements to setup.py to try and work out what's going on.

codebuk commented 9 years ago

Jim,

The log posted includes 2 attempts -a run without and then with -builtin. I manually edited setup.py.

Here it is set back to the original with 'print swig_version:

bash-4.2$ python setup.py --verbose build
2.0.11
running build
running build_ext
building '_gphoto2_abilities_list' extension
swigging src/gphoto2/lib/gphoto2_abilities_list.i to src/gphoto2/lib/gphoto2_abilities_list_wrap.c
swig -python -nodefaultctor -O -Wextra -Werror -MMD -DGPHOTO2_25 -I/usr/include -o src/gphoto2/lib/gphoto2_abilities_list_wrap.c src/gphoto2/lib/gphoto2_abilities_list.i
creating build
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/src
creating build/temp.linux-x86_64-2.7/src/gphoto2
creating build/temp.linux-x86_64-2.7/src/gphoto2/lib
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c src/gphoto2/lib/gphoto2_abilities_list_wrap.c -o build/temp.linux-x86_64-2.7/src/gphoto2/lib/gphoto2_abilities_list_wrap.o -O3 -Wno-unused-variable -Wno-strict-prototypes -Werror -DGPHOTO2_25
src/gphoto2/lib/gphoto2_abilities_list_wrap.c: In function ‘_wrap_CameraAbilitiesList___len__’:
src/gphoto2/lib/gphoto2_abilities_list_wrap.c:3398:5: error: implicit declaration of function ‘struct__CameraAbilitiesList___len__’ [-Werror=implicit-function-declaration]
     result = (int)struct__CameraAbilitiesList___len__(arg1);
     ^
src/gphoto2/lib/gphoto2_abilities_list_wrap.c: In function ‘_wrap_CameraAbilitiesList_count’:
src/gphoto2/lib/gphoto2_abilities_list_wrap.c:3694:5: error: implicit declaration of function ‘struct__CameraAbilitiesList_count’ [-Werror=implicit-function-declaration]
     result = (int)struct__CameraAbilitiesList_count(arg1);
     ^
src/gphoto2/lib/gphoto2_abilities_list_wrap.c: In function ‘_wrap_CameraAbilitiesList_lookup_model’:
src/gphoto2/lib/gphoto2_abilities_list_wrap.c:3733:5: error: implicit declaration of function ‘struct__CameraAbilitiesList_lookup_model’ [-Werror=implicit-function-declaration]
     result = (int)struct__CameraAbilitiesList_lookup_model(arg1,(char const *)arg2);
     ^
cc1: all warnings being treated as errors
error: command 'gcc' failed with exit status 1
bash-4.2$ 
jim-easterbrook commented 9 years ago

Ah, now I see. It's not the "(Py_ssize_t)offsetof(SwigPyObject, dict)" error at all, but something else that doesn't go away when -builtin is used. I'll look into it.

codebuk commented 9 years ago

Jim,

Many thanks. I can give you access to the system if it makes it any easier or if there is anything else I can do just yell out.

Dan

jim-easterbrook commented 9 years ago

It looks as if the '-builtin' bug isn't the only thing that changed in SWIG 2.0.11 (I'm on 2.0.10). Your missing functions such as struct__CameraAbilitiesList___len__ are called _CameraAbilitiesList___len__ in my version. I think it might be possible to add extra definitions in macros.i. Can you add int (*struct ## _ ## type ## _ ## member)() = function; immediately after line 143 in macros.i and try again.

codebuk commented 9 years ago

Jim,

Much better but a similar error later on:

  building '_gphoto2_widget' extension
swigging src/gphoto2/lib/gphoto2_widget.i to src/gphoto2/lib/gphoto2_widget_wrap.c
swig -python -nodefaultctor -O -Wextra -Werror -MMD -DGPHOTO2_25 -I/usr/include -o src/gphoto2/lib/gphoto2_widget_wrap.c src/gphoto2/lib/gphoto2_widget.i
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c src/gphoto2/lib/gphoto2_widget_wrap.c -o build/temp.linux-x86_64-2.7/src/gphoto2/lib/gphoto2_widget_wrap.o -O3 -Wno-unused-variable -Wno-strict-prototypes -Werror -DGPHOTO2_25
src/gphoto2/lib/gphoto2_widget_wrap.c: In function ‘_wrap_CameraWidget_set_value’:
src/gphoto2/lib/gphoto2_widget_wrap.c:4135:3: error: implicit declaration of function ‘struct__CameraWidget_set_value’ [-Werror=implicit-function-declaration]
   result = (PyObject *)struct__CameraWidget_set_value(arg1,arg2);
   ^
src/gphoto2/lib/gphoto2_widget_wrap.c:4135:12: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
   result = (PyObject *)struct__CameraWidget_set_value(arg1,arg2);
            ^
src/gphoto2/lib/gphoto2_widget_wrap.c: In function ‘_wrap_CameraWidget_get_value’:
src/gphoto2/lib/gphoto2_widget_wrap.c:4158:3: error: implicit declaration of function ‘struct__CameraWidget_get_value’ [-Werror=implicit-function-declaration]
   result = (PyObject *)struct__CameraWidget_get_value(arg1);
   ^
src/gphoto2/lib/gphoto2_widget_wrap.c:4158:12: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
   result = (PyObject *)struct__CameraWidget_get_value(arg1);
            ^
cc1: all warnings being treated as errors
error: command 'gcc' failed with exit status 1
bash-4.2$ 
jim-easterbrook commented 9 years ago

Yup, same problem. My "hand crafted" helper functions need to match SWIG's naming scheme and it must have changed. Commit 667efe9 should do the right thing.