obj.h
obj.h copied to clipboard
How to use it in emscripten?
I want to use it in emscripten
In theory, LLVM/Clang's C compiler can compile those examples fine, so there is no problem to compile them in Emscripten. But I'm not sure about they can run correctly, in machine code level.
You should use C++ instead.
But in the obj.h it can not support the platform,
Did you get compilation errors in this header?
no compilation errors , just show not support
#endif
#define __OBJ_ACTIV(ptr, size)
(VirtualProtect(ptr, size, PAGE_EXECUTE_READWRITE, &((unsigned long){ 0 })) != 0)
#else
#error "This OS is not supported!"
#endif
#if defined(x86_64) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64) #define __OBJ_X64 1 #elif defined(__i386) || defined(i386) || defined(_M_IX86) #define __OBJ_X86 1 #else #error This architecture is not supported! #endif VirtualProtect this function I can not find
PAGE_SHIFT undefine
no compilation errors , just show not support
cc: error "This OS is not supported!"
cc: error "This architecture is not supported!"
If you got errors of the header checks, you can disable these #error
code.
https://github.com/small-c/obj.h/blob/c9f00cf063fb1f54a5e5c87a60af69564e719a8f/obj.h#L66-L76
In CPU arch checking, you should define one. For example, your web browser runtime is 64-bit (x86-64):
#define __OBJ_X64
Remember this library still does not support ARM64 (includes Apple M1/M2 Sillicon).
VirtualProtect this function I can not find
This is a win32 API, in Emscripten you should use mprotect() instead.
PAGE_SHIFT undefine
This value usually is 12, you can find it in compiler's include files.
./obj.h:101:71: error: use of undeclared identifier '__OBJ_CLOFNNUM' ...if (*(size_t *)((uintptr_t)prototype + offset) == (size_t)__OBJ_CLOFNNUM)
^
./obj.h:142:30: error: use of undeclared identifier 'asmc'; did you mean 'asin'
ihsize = offset + sizeof(asmc);
^~~~
asin
D:\cenv\emsdk\upstream\emscripten\cache\sysroot/include\math.h:143:13: note: 'asin' declared here double asin(double); ^ In file included from ./player.c:2: In file included from ./skillButton.h:4: In file included from ./textTexture.h:3: ./obj.h:145:10: error: use of undeclared identifier 'PAGE_SHIFT'; did you mean 'KMOD_SHIFT'? if (!__OBJ_ACTIV(code, ihsize)) { ^ ./obj.h:49:40: note: expanded from macro '__OBJ_ACTIV' (mprotect((void *)(((size_t)ptr >> PAGE_SHIFT) << PAGE_SHIFT), size... ^ D:\cenv\emsdk\upstream\emscripten\cache\sysroot\include\SDL2/SDL_keycode.h:344: : note: 'KMOD_SHIFT' declared here KMOD_SHIFT = KMOD_LSHIFT | KMOD_RSHIFT, ^ In file included from ./player.c:2: In file included from ./skillButton.h:4: In file included from ./textTexture.h:3: ./obj.h:145:10: error: use of undeclared identifier 'PAGE_SHIFT'; did you mean 'KMOD_SHIFT'? if (!__OBJ_ACTIV(code, ihsize)) { ^ ./obj.h:49:55: note: expanded from macro '__OBJ_ACTIV' (mprotect((void *)(((size_t)ptr >> PAGE_SHIFT) << PAGE_SHIFT), size... ^ D:\cenv\emsdk\upstream\emscripten\cache\sysroot\include\SDL2/SDL_keycode.h:344: : note: 'KMOD_SHIFT' declared here KMOD_SHIFT = KMOD_LSHIFT | KMOD_RSHIFT, ^ In file included from ./player.c:2: In file included from ./skillButton.h:4: In file included from ./textTexture.h:3: ./obj.h:157:5: error: use of undeclared identifier 'asmc' asmc.data = (uintptr_t)data; ^ ./obj.h:159:41: error: use of undeclared identifier 'asmc'; did you mean 'asin'
memcpy(code + offset, &asmc, sizeof(asmc));
^~~~
asin
D:\cenv\emsdk\upstream\emscripten\cache\sysroot/include\math.h:143:13: note: 'asin' declared here double asin(double); ^ In file included from ./player.c:2: In file included from ./skillButton.h:4: In file included from ./textTexture.h:3: ./obj.h:159:28: error: use of undeclared identifier 'asmc'; did you mean 'asin'
memcpy(code + offset, &asmc, sizeof(asmc));
^~~~
index.js:2333 could't find closure declaration at prototype function (0x25)!could't find closure declaration at prototype function (0x26)!could't find closure declaration at prototype function (0x27)!could't find closure declaration at prototype function (0x28)!could't find closure declaration at prototype function (0x29)![obj.h] error: could't implement the method 'show'! put_char @ index.js:2333 index.js:2333 could't find closure declaration at prototype function (0x1b)!could't find closure declaration at prototype function (0x1c)!could't find closure declaration at prototype function (0x1d)!could't find closure declaration at prototype function (0x1e)!could't find closure declaration at prototype function (0x1f)![obj.h] error: could't implement the method 'show'!
when i run it
These errors related to CPU arch and function ABI, also wasm code when Emscripten compiles. I'll test them soon.
Leave your system information here, about CPU, OS, web browser name and Emscripten version.
These errors related to CPU arch and function ABI, also wasm code when Emscripten compiles. I'll test them soon.
Leave your system information here, about CPU, OS, web browser name and Emscripten version.
windows7 x64 Intel core i5 2467m [email protected] chrome 108.0.5359.125 (64 位) emscripten version 3.1.7 Thank you
Anything new? @nomi-san