HaxeFoundation / hxcpp

Runtime files for c++ backend for haxe
Other
298 stars 191 forks source link

Sys.cpp:174:34: error: cannot initialize a parameter of type 'const char *' with an rvalue of type 'const wchar_t *' #883

Open sonygod opened 4 years ago

sonygod commented 4 years ago

build with emcc

-D emscripten

got this error.

haxe:4.0.5

 hxcpp:git

Error: shared:WARNING: ignoring -fPIC flag when not building with SIDE_MODULE or MAIN_MODULE
/root/haxe/haxelib/hxcpp/git/src/hx/libs/std/Sys.cpp:174:14: error: use of undeclared identifier '_wsetlocale'; did you mean 'setlocale'?
      return _wsetlocale(LC_TIME,l.wchar_str());
             ^~~~~~~~~~~
             setlocale
/root/test/emsdk/upstream/emscripten/system/include/libc/locale.h:53:7: note: 'setlocale' declared here
char *setlocale (int, const char *);
      ^
/root/haxe/haxelib/hxcpp/git/src/hx/libs/std/Sys.cpp:174:34: error: cannot initialize a parameter of type 'const char *' with an rvalue of type 'const wchar_t *'
      return _wsetlocale(LC_TIME,l.wchar_str());
                                 ^~~~~~~~~~~~~
/root/test/emsdk/upstream/emscripten/system/include/libc/locale.h:53:35: note: passing argument to parameter here
char *setlocale (int, const char *);
                                  ^
2 errors generated.
sonygod commented 4 years ago

after revert master branch,still get this error

sonygod commented 4 years ago

test code here

with this lib : https://github.com/ianharrigan/hxWebSockets

and MyHandler.hx is here.

https://github.com/ianharrigan/hxWebSockets/blob/master/Examples/sys-server/src/MyHandler.hx

package;
import hx.ws.WebSocketServer;
import server.MyHandler;
#if emscripten
@:buildXml("

    <linker id='exe' exe='em++'>
    <flag value='-s' />
    <flag value='WASM=1' />
</linker>

    ")
@:cppFileCode('
    #include <emscripten/bind.h>
    using namespace emscripten;

    EMSCRIPTEN_BINDINGS(my_class_example) {
    class_<EMCCMain>("EMCCMain")
    .class_function("sum", &EMCCMain_obj::Sum)
    .class_function("fb", &EMCCMain_obj::Fb)
    .class_function("fb2", &EMCCMain_obj::Fb2);
    }
    ')
#end

/**
 * wasm example.
 */
class EMCCMain {
    public static function Fb(n:Int) {
        if (n == 0) {
            return 0;
        }

        if (n == 1) {
            return 1;
        }
        return Fb(n - 1) + Fb(n - 2);
    }

    public static function Fb2(first:Float, second:Float, n:Int):Float {
        if (n < 2) {
            return n;
        }

        if (n == 2) {
            return first + second;
        }
        var result = Fb2(second, first + second, n - 1);

        // trace('first=$first second=$second ,n=$n result=$result');
        return result;
    }

    public static function Sum(a:Int, b:Int):Int {
        return a + b;
    }

    public static function main() {
        trace("hello wasm1");

        var port = 9007;
        var server = new WebSocketServer<MyHandler>("0.0.0.0", port, 30);

        trace("server ready start " + port);

        server.start();
    }
}
barisyild commented 4 years ago

Information: C:/HaxeToolkit/haxe/lib/hxcpp/4,0,64/src/hx/libs/std/Sys.cpp:174:14: error: use of undeclared identifier '_wsetlocale'; did you mean 'setlocale'? Information: return _wsetlocale(LC_TIME,l.wchar_str()); Information: C:\emsdk\upstream\emscripten\system\include\libc\locale.h:53:7: note: 'setlocale' declared here Information: char setlocale (int, const char ); Information: C:/HaxeToolkit/haxe/lib/hxcpp/4,0,64/src/hx/libs/std/Sys.cpp:174:34: error: cannot initialize a parameter of type 'const char ' with an rvalue of type 'const wchar_t ' Information: C:\emsdk\upstream\emscripten\system\include\libc\locale.h:53:35: note: passing argument to parameter here

Same Issue

barisyild commented 4 years ago

Duplicate of #867