Tux

...making Linux just a little more fun!

Talkback:147/pfeiffer.html

[ In reference to "Tips on Using Unicode with C/C++" in LG#147 ]

Jimmy O'Regan [joregan at gmail.com]


Thu, 20 Mar 2008 02:41:13 +0000

I was reminded of Ren?'s article while trying to get Apertium to compile with Cygwin, because Cygwin lacks wide string support in g++. I tried to find a canned piece of m4, to give a warning about this at configure time instead of compile time, but, alas, I couldn't find anything and had to write something myself.

Does anyone know enough about configure etc. to find any obvious problems with this?

# Check for wide strings
AC_DEFUN([AC_CXX_WSTRING],[
  AC_CACHE_CHECK(whether the compiler supports wide strings,
  ac_cv_cxx_wstring,
  [AC_LANG_SAVE
   AC_LANG_CPLUSPLUS
   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <string>]],[[
std::wstring test = L"test";
int main () {}
   ]])],
   [ac_cv_cxx_wstring=yes], [ac_cv_cxx_wstring=no])
   AC_LANG_RESTORE
  ])
])
 
AC_CXX_WSTRING
 
if test "$ac_cv_cxx_wstring" = no
then
  AC_MSG_ERROR([Missing wide string support])
fi


Top    Back


René Pfeiffer [lynx at luchs.at]


Thu, 20 Mar 2008 16:25:21 +0100

On Mar 20, 2008 at 0241 +0000, Jimmy O'Regan appeared and said:

> [...]
> Does anyone know enough about configure etc. to find any obvious
> problems with this?
>=20
> ```
> # Check for wide strings
> AC_DEFUN([AC_CXX_WSTRING],[
>   AC_CACHE_CHECK(whether the compiler supports wide strings,
>   ac_cv_cxx_wstring, [...]

Hm, do you have the output in config.log at hand? I am not well fluent in autoconf. You can also send me the configure script and I'll run it (on non-Cygwin though) to see what tests it checks.

Best, René.


Top    Back


Jimmy O'Regan [joregan at gmail.com]


Thu, 20 Mar 2008 16:12:48 +0000

On 20/03/2008, René Pfeiffer <lynx@luchs.at> wrote:

> On Mar 20, 2008 at 0241 +0000, Jimmy O'Regan appeared and said:
>  > [...]
>
> > Does anyone know enough about configure etc. to find any obvious
>  > problems with this?
>  >
>  > ```
>  > # Check for wide strings
>  > AC_DEFUN([AC_CXX_WSTRING],[
>  >   AC_CACHE_CHECK(whether the compiler supports wide strings,
>
> >   ac_cv_cxx_wstring, [...]
>
>  Hm, do you have the output in config.log at hand? I am not well fluent
>  in autoconf. You can also send me the configure script and I'll run it
>  (on non-Cygwin though) to see what tests it checks.

Well, thanks to your mention of config.log, I found one error myself - I misunderstood how AC_COMPILE_IFELSE works:

configure:3635: checking whether the compiler supports wide strings
configure:3671: g++ -c -g -O2  conftest.cpp >&5
conftest.cpp: In function `int main()':
conftest.cpp:14: error: `wstring' is not a member of `std'
conftest.cpp:14: error: expected `;' before "test"
conftest.cpp:15: error: expected primary-expression before "int"
conftest.cpp:15: error: expected `;' before "int"
configure:3677: $? =3D 1
configure: failed program was:
| /* confdefs.h.  */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define STDC_HEADERS 1
| /* end confdefs.h.  */
| #include <string>
| int
| main ()
| {
|
| std::wstring test =3D L"test";
| int main () {}
|
|   ;
|   return 0;
| }
configure:3699: result: no
configure:3705: error: Missing wide string support

so, having removed the offending 'main () {}' line, it seems to fail for the right reasons:

configure:3635: checking whether the compiler supports wide strings
configure:3670: g++ -c -g -O2  conftest.cpp >&5
conftest.cpp: In function `int main()':
conftest.cpp:14: error: `wstring' is not a member of `std'
conftest.cpp:14: error: expected `;' before "test"
configure:3676: $? =3D 1
configure: failed program was:
| /* confdefs.h.  */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define STDC_HEADERS 1
| /* end confdefs.h.  */
| #include <string>
| int
| main ()
| {
|
| std::wstring test =3D L"test";
|
|   ;
|   return 0;
| }
configure:3698: result: no
configure:3704: error: Missing wide string support

I've attached the whole log, and the dummy configure.in I used to test it.


Top    Back