2

我已经成功生成了所需的 .py 和 .cpp 文件:

swig -c++ -python sf_c_api.i

但现在我正在尝试制作共享对象(.so)并且我被错误所淹没。

g++ -Wall -g -fPIC -I/usr/include/python2.6 -c atob.c fish.c maby_swap.c pwd_file.c pwd.c setup_fish.c shs.c sf_c_api.cpp sha1.cpp sf_c_api_wrap.cpp

任何人都可以对这个 g++ 输出做出正面或反面吗?

In file included from /usr/include/python2.6/Python.h:8,
                 from sf_c_api_wrap.cpp:149:
/usr/include/python2.6/pyconfig.h:1038:1: warning: "_XOPEN_SOURCE" redefined
<built-in>: warning: this is the location of the previous definition
In file included from /usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/postypes.h:42,
                 from /usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h:42,
                 from /usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/string:42,
                 from /usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/stdexcept:39,
                 from sf_c_api_wrap.cpp:3024:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:143: error: ‘::btowc’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:148: error: ‘::fwide’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:149: error: ‘::fwprintf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:150: error: ‘::fwscanf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:153: error: ‘::mbrlen’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:154: error: ‘::mbrtowc’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:155: error: ‘::mbsinit’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:156: error: ‘::mbsrtowcs’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:159: error: ‘::swprintf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:160: error: ‘::swscanf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:162: error: ‘::vfwprintf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:166: error: ‘::vswprintf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:170: error: ‘::vwprintf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:174: error: ‘::wcrtomb’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:185: error: ‘::wcsrtombs’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:195: error: ‘::wctob’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:196: error: ‘::wmemcmp’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:197: error: ‘::wmemcpy’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:198: error: ‘::wmemmove’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:199: error: ‘::wmemset’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:200: error: ‘::wprintf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:201: error: ‘::wscanf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:205: error: ‘::wcsstr’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:206: error: ‘::wmemchr’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar: In function ‘wchar_t* std::wcsstr(wchar_t*, const wchar_t*)’:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:223: error: invalid conversion from ‘const wchar_t*’ to ‘wchar_t*’
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:223: error:   initializing argument 1 of ‘wchar_t* std::wcsstr(wchar_t*, const wchar_t*)’
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar: In function ‘wchar_t* std::wmemchr(wchar_t*, wchar_t, size_t)’:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:227: error: invalid conversion from ‘const wchar_t*’ to ‘wchar_t*’
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:227: error:   initializing argument 1 of ‘wchar_t* std::wmemchr(wchar_t*, wchar_t, size_t)’
In file included from /usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/string:42,
                 from /usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/stdexcept:39,
                 from sf_c_api_wrap.cpp:3024:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h: In static member function ‘static int std::char_traits<wchar_t>::compare(const wchar_t*, const wchar_t*, size_t)’:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h:330: error: ‘wmemcmp’ was not declared in this scope/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h: In static member function ‘static const wchar_t* std::char_traits<wchar_t>::find(const wchar_t*, size_t, const wchar_t&)’:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h:338: error:   initializing argument 1 of ‘wchar_t* std::wmemchr(wchar_t*, wchar_t, size_t)’
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h: In static member function ‘static wchar_t* std::char_traits<wchar_t>::move(wchar_t*, const wchar_t*, size_t)’:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h:342: error: ‘wmemmove’ was not declared in this scope
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h: In static member function ‘static wchar_t* std::char_traits<wchar_t>::copy(wchar_t*, const wchar_t*, size_t)’:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h:346: error: ‘wmemcpy’ was not declared in this scope
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h: In static member function ‘static wchar_t* std::char_traits<wchar_t>::assign(wchar_t*, size_t, wchar_t)’:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h:350: error: ‘wmemset’ was not declared in this scope

/../include/c++/4.4.4/bits/char_traits.h:338: error: invalid conversion from ‘const wchar_t*’ to ‘wchar_t*’
4

1 回答 1

3

我找到了解决方案。

问题是在solaris下:

如果-D_XOPEN_SOURCE_EXTENDED=1, g++ 甚至不能编译一个空的#includes <iostream>. 如果未定义,则 gcc 无法编译 C 代码。

[来源]

并从/usr/include/python2.6/pyconfig.h

/* Define to activate Unix95-and-earlier features */
#define _XOPEN_SOURCE_EXTENDED 1

删除 XOPEN 定义解决了我的问题。

于 2013-01-16T15:33:12.947 回答