Hi.
Let me first note, that I've seen a similar topic on this forum on the same matter. I felt it didn't propose any reasonable answer to the problem, therefore I'm opening a new thread.
I'm in the process of making a cross platform game engine, using squirrel as scripting language, and Sqrat to bind it. I'm not able to compile squirrel in such a way that it uses wchar_t for strings on Linux using gcc version 4.6.1. It works just like expected on windows using VS2010.
When adding the SQUNICODE define to the Makefile in SQUIRREL3/squirrel/Makefile,
Code:
gcc -O2 -DSQUNICODE -fno-exceptions -fno-rtti -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ) $(DEFS)
the compiler reports several errors (amongst others) regarding squirrel.h line 121:
Code:
typedef unsigned short wchar_t;
Upon commenting out this line, the rest of the errors were related to wide string functions, such as swprintf, wcsstr and wcstod.
I was under the assumption that these were caused by missing #include <wchar.t>. I then added this to sqpcheader.h, butthis still produced errors such as
Code:
sqapi.cpp: In function ‘SQInteger sq_aux_invalidtype(HSQUIRRELVM, SQObjectType)’:
sqapi.cpp:37:84: error: invalid conversion from ‘const wchar_t*’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
/usr/include/x86_64-linux-gnu/bits/wchar2.h:286:1: error: initializing argument 2 of ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’ [-fpermissive]
which from what I can see is due to missing the size parameter in the function call.
Other errors such as
Code:
sqlexer.cpp:258:27: error: ‘iswdigit’ was not declared in this scope
sqlexer.cpp:262:32: error: ‘iswalpha’ was not declared in this scope
sqlexer.cpp:268:26: error: ‘iswcntrl’ was not declared in this scope
were corrected by adding #include <wctype.h> to sqpcheader.h.
The remaining compile log in its entirety:
Code:
gcc -O2 -DSQUNICODE -fno-exceptions -fno-rtti -Wall -fno-strict-aliasing -c sqapi.cpp sqbaselib.cpp sqfuncstate.cpp sqdebug.cpp sqlexer.cpp sqobject.cpp sqcompiler.cpp sqstate.cpp sqtable.cpp sqmem.cpp sqvm.cpp sqclass.cpp -I../include -I. -Iinclude
sqapi.cpp: In function ‘SQInteger sq_aux_invalidtype(HSQUIRRELVM, SQObjectType)’:
sqapi.cpp:37:84: error: invalid conversion from ‘const wchar_t*’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
/usr/include/x86_64-linux-gnu/bits/wchar2.h:286:1: error: initializing argument 2 of ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’ [-fpermissive]
sqbaselib.cpp: In function ‘bool str2num(const SQChar*, SQObjectPtr&)’:
sqbaselib.cpp:26:45: error: ‘_wcstoi64’ was not declared in this scope
sqdebug.cpp: In member function ‘void SQVM::Raise_Error(const SQChar*, ...)’:
sqdebug.cpp:62:72: error: invalid conversion from ‘const SQChar* {aka const wchar_t*}’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
sqdebug.cpp:62:72: error: cannot convert ‘__va_list_tag*’ to ‘const wchar_t*’ for argument ‘3’ to ‘int vswprintf(wchar_t*, size_t, const wchar_t*, __va_list_tag*)’
sqdebug.cpp: In member function ‘SQString* SQVM::PrintObjVal(const SQObjectPtr&)’:
sqdebug.cpp:77:69: error: invalid conversion from ‘const wchar_t*’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
/usr/include/x86_64-linux-gnu/bits/wchar2.h:286:1: error: initializing argument 2 of ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’ [-fpermissive]
sqdebug.cpp:77:69: error: invalid conversion from ‘SQInteger {aka long long int}’ to ‘const wchar_t*’ [-fpermissive]
/usr/include/x86_64-linux-gnu/bits/wchar2.h:286:1: error: initializing argument 3 of ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’ [-fpermissive]
sqdebug.cpp:81:65: error: invalid conversion from ‘const wchar_t*’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
sqdebug.cpp:81:65: error: cannot convert ‘const SQFloat {aka const float}’ to ‘const wchar_t*’ for argument ‘3’ to ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’
sqcompiler.cpp: In member function ‘void SQCompiler::Error(const SQChar*, ...)’:
sqcompiler.cpp:92:25: error: invalid conversion from ‘const SQChar* {aka const wchar_t*}’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
sqcompiler.cpp:92:25: error: cannot convert ‘__va_list_tag*’ to ‘const wchar_t*’ for argument ‘3’ to ‘int vswprintf(wchar_t*, size_t, const wchar_t*, __va_list_tag*)’
sqvm.cpp: In member function ‘bool SQVM::ToString(const SQObjectPtr&, SQObjectPtr&)’:
sqvm.cpp:278:60: error: invalid conversion from ‘const wchar_t*’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
sqvm.cpp:278:60: error: cannot convert ‘const SQFloat {aka const float}’ to ‘const wchar_t*’ for argument ‘3’ to ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’
sqvm.cpp:281:67: error: invalid conversion from ‘const wchar_t*’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
/usr/include/x86_64-linux-gnu/bits/wchar2.h:286:1: error: initializing argument 2 of ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’ [-fpermissive]
sqvm.cpp:281:67: error: invalid conversion from ‘SQInteger {aka long long int}’ to ‘const wchar_t*’ [-fpermissive]
/usr/include/x86_64-linux-gnu/bits/wchar2.h:286:1: error: initializing argument 3 of ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’ [-fpermissive]
sqvm.cpp:284:61: error: invalid conversion from ‘const wchar_t*’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
sqvm.cpp:284:61: error: too few arguments to function ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’
/usr/include/x86_64-linux-gnu/bits/wchar2.h:286:1: note: declared here
sqvm.cpp:303:91: error: invalid conversion from ‘const wchar_t*’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
/usr/include/x86_64-linux-gnu/bits/wchar2.h:286:1: error: initializing argument 2 of ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’ [-fpermissive]
make: *** [sq32] Error 1
maestro@frosty:~/Downloads/sq/SQUIRREL3/squirrel$ make > log
sqapi.cpp: In function ‘SQInteger sq_aux_invalidtype(HSQUIRRELVM, SQObjectType)’:
sqapi.cpp:37:84: error: invalid conversion from ‘const wchar_t*’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
/usr/include/x86_64-linux-gnu/bits/wchar2.h:286:1: error: initializing argument 2 of ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’ [-fpermissive]
sqbaselib.cpp: In function ‘bool str2num(const SQChar*, SQObjectPtr&)’:
sqbaselib.cpp:26:45: error: ‘_wcstoi64’ was not declared in this scope
sqdebug.cpp: In member function ‘void SQVM::Raise_Error(const SQChar*, ...)’:
sqdebug.cpp:62:72: error: invalid conversion from ‘const SQChar* {aka const wchar_t*}’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
sqdebug.cpp:62:72: error: cannot convert ‘__va_list_tag*’ to ‘const wchar_t*’ for argument ‘3’ to ‘int vswprintf(wchar_t*, size_t, const wchar_t*, __va_list_tag*)’
sqdebug.cpp: In member function ‘SQString* SQVM::PrintObjVal(const SQObjectPtr&)’:
sqdebug.cpp:77:69: error: invalid conversion from ‘const wchar_t*’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
/usr/include/x86_64-linux-gnu/bits/wchar2.h:286:1: error: initializing argument 2 of ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’ [-fpermissive]
sqdebug.cpp:77:69: error: invalid conversion from ‘SQInteger {aka long long int}’ to ‘const wchar_t*’ [-fpermissive]
/usr/include/x86_64-linux-gnu/bits/wchar2.h:286:1: error: initializing argument 3 of ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’ [-fpermissive]
sqdebug.cpp:81:65: error: invalid conversion from ‘const wchar_t*’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
sqdebug.cpp:81:65: error: cannot convert ‘const SQFloat {aka const float}’ to ‘const wchar_t*’ for argument ‘3’ to ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’
sqcompiler.cpp: In member function ‘void SQCompiler::Error(const SQChar*, ...)’:
sqcompiler.cpp:92:25: error: invalid conversion from ‘const SQChar* {aka const wchar_t*}’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
sqcompiler.cpp:92:25: error: cannot convert ‘__va_list_tag*’ to ‘const wchar_t*’ for argument ‘3’ to ‘int vswprintf(wchar_t*, size_t, const wchar_t*, __va_list_tag*)’
sqvm.cpp: In member function ‘bool SQVM::ToString(const SQObjectPtr&, SQObjectPtr&)’:
sqvm.cpp:278:60: error: invalid conversion from ‘const wchar_t*’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
sqvm.cpp:278:60: error: cannot convert ‘const SQFloat {aka const float}’ to ‘const wchar_t*’ for argument ‘3’ to ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’
sqvm.cpp:281:67: error: invalid conversion from ‘const wchar_t*’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
/usr/include/x86_64-linux-gnu/bits/wchar2.h:286:1: error: initializing argument 2 of ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’ [-fpermissive]
sqvm.cpp:281:67: error: invalid conversion from ‘SQInteger {aka long long int}’ to ‘const wchar_t*’ [-fpermissive]
/usr/include/x86_64-linux-gnu/bits/wchar2.h:286:1: error: initializing argument 3 of ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’ [-fpermissive]
sqvm.cpp:284:61: error: invalid conversion from ‘const wchar_t*’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
sqvm.cpp:284:61: error: too few arguments to function ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’
/usr/include/x86_64-linux-gnu/bits/wchar2.h:286:1: note: declared here
sqvm.cpp:303:91: error: invalid conversion from ‘const wchar_t*’ to ‘size_t {aka long unsigned int}’ [-fpermissive]
/usr/include/x86_64-linux-gnu/bits/wchar2.h:286:1: error: initializing argument 2 of ‘int swprintf(wchar_t*, size_t, const wchar_t*, ...)’ [-fpermissive]
make: *** [sq32] Error 1
As this is a 64-bit OS, I also tried passing the -m32 flag to gcc in the makefile, but this only changed the include paths of files such as wchar2.h to its 32-bit equivalent, leaving the same errors as before. I don't belive this is the cause, but I have yet to confirm that.
Since most of these functions are defined through macros, it might be best to add another abstraction to them, so if gcc is used to compile, the string operations use an additional size parameter that can be left out on other platforms.
I really hope it's possible to provide a patch for this. I could do it myself, but I'm not proficient enough in making diffs and I'd rather have someone with the full picture provide a fix since these operations seems rather vital to make squirrel work correctly. It might also just be something I'm completely missing or misunderstanding, even though I've done some extensive googling on this matter.
- Maestro