Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Embind & std::bind #24290

Copy link
Copy link
Open
Open
Copy link
@GulgDev

Description

@GulgDev
Issue body actions

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.6 (1ddaae4d2d6dfbb678ecc193bc988820d1fc4633)
clang version 21.0.0git (https:/github.com/llvm/llvm-project 4775e6d9099467df9363e1a3cd5950cc3d2fde05)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:\Users\user\Downloads\emsdk\upstream\bin

Failing command line in full:

> emcc main.cpp -lembind
main.cpp:12:5: error: no matching function for call to 'function'
   12 |     function<int(int, int)>("add5", std::bind(&add, 5, std::placeholders::_1));
      |     ^~~~~~~~~~~~~~~~~~~~~~~
C:\Users\user\Downloads\emsdk\upstream\emscripten\cache\sysroot/include\emscripten/bind.h:666:6: note: candidate template ignored: substitution failure [with ReturnType = int (int, int)]: function    
      cannot return function type 'int (int, int)'
  666 | void function(const char* name, ReturnType (*fn)(Args...), Policies...) {
      |      ^                          ~~~~~~~~~~
1 error generated.
emcc: error: 'C:/Users/user/Downloads/emsdk/upstream/bin\clang.exe -target wasm32-unknown-emscripten -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --sysroot=C:\Users\user\Downloads\emsdk\upstream\emscripten\cache\sysroot -DEMSCRIPTEN -Xclang -iwithsysroot/include\fakesdl -Xclang -iwithsysroot/include\compat -c main.cpp -o C:\Users\user\AppData\Local\Temp\emscripten_temp_z_8dp2sz\main_0.o' failed (returned 1)

Full link command and output with -v appended:

> emcc main.cpp -lembind -v
 "C:/Users/user/Downloads/emsdk/upstream/bin\clang.exe" -target wasm32-unknown-emscripten -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --sysroot=C:\Users\user\Downloads\emsdk\upstream\emscripten\cache\sysroot -DEMSCRIPTEN -Xclang -iwithsysroot/include\fakesdl -Xclang -iwithsysroot/include\compat -v -c main.cpp -o C:\Users\user\AppData\Local\Temp\emscripten_temp_qso33ae2\main_0.o
clang version 21.0.0git (https:/github.com/llvm/llvm-project 4775e6d9099467df9363e1a3cd5950cc3d2fde05)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:\Users\user\Downloads\emsdk\upstream\bin
 (in-process)
 "C:\\Users\\user\\Downloads\\emsdk\\upstream\\bin\\clang.exe" -cc1 -triple wasm32-unknown-emscripten -emit-obj -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -fvisibility=hidden -debugger-tuning=gdb "-fdebug-compilation-dir=C:\\Users\\user\\Desktop\\Projects\\other\\embind-std-bind-repro" -v "-fcoverage-compilation-dir=C:\\Users\\user\\Desktop\\Projects\\other\\embind-std-bind-repro" -resource-dir "C:\\Users\\user\\Downloads\\emsdk\\upstream\\lib\\clang\\21" -D EMSCRIPTEN -isysroot "C:\\Users\\user\\Downloads\\emsdk\\upstream\\emscripten\\cache\\sysroot" -internal-isystem "C:\\Users\\user\\Downloads\\emsdk\\upstream\\emscripten\\cache\\sysroot/include/wasm32-emscripten/c++/v1" -internal-isystem "C:\\Users\\user\\Downloads\\emsdk\\upstream\\emscripten\\cache\\sysroot/include/c++/v1" -internal-isystem "C:\\Users\\user\\Downloads\\emsdk\\upstream\\lib\\clang\\21\\include" -internal-isystem "C:\\Users\\user\\Downloads\\emsdk\\upstream\\emscripten\\cache\\sysroot/include/wasm32-emscripten" -internal-isystem "C:\\Users\\user\\Downloads\\emsdk\\upstream\\emscripten\\cache\\sysroot/include" -fdeprecated-macro -ferror-limit 19 -fmessage-length=200 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fignore-exceptions -fexceptions -fcolor-diagnostics "-iwithsysroot/include\\fakesdl" "-iwithsysroot/include\\compat" -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o "C:\\Users\\user\\AppData\\Local\\Temp\\emscripten_temp_qso33ae2\\main_0.o" -x c++ main.cpp
clang -cc1 version 21.0.0git based upon LLVM 21.0.0git default target x86_64-pc-windows-msvc
ignoring nonexistent directory "C:\Users\user\Downloads\emsdk\upstream\emscripten\cache\sysroot/include/wasm32-emscripten/c++/v1"
ignoring nonexistent directory "C:\Users\user\Downloads\emsdk\upstream\emscripten\cache\sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
 C:\Users\user\Downloads\emsdk\upstream\emscripten\cache\sysroot/include\fakesdl
 C:\Users\user\Downloads\emsdk\upstream\emscripten\cache\sysroot/include\compat
 C:\Users\user\Downloads\emsdk\upstream\emscripten\cache\sysroot/include/c++/v1
 C:\Users\user\Downloads\emsdk\upstream\lib\clang\21\include
 C:\Users\user\Downloads\emsdk\upstream\emscripten\cache\sysroot/include
End of search list.
main.cpp:12:5: error: no matching function for call to 'function'
   12 |     function("add1", std::bind(&add, 1, std::placeholders::_1)); // error: no matching function for call to 'function'
      |     ^~~~~~~~
C:\Users\user\Downloads\emsdk\upstream\emscripten\cache\sysroot/include\emscripten/bind.h:666:6: note: candidate template ignored: could not match 'ReturnType (*)(Args...)' against
      '__bind<int (*)(int, int), int, const __ph<1> &>'
  666 | void function(const char* name, ReturnType (*fn)(Args...), Policies...) {
      |      ^
1 error generated.
emcc: error: 'C:/Users/user/Downloads/emsdk/upstream/bin\clang.exe -target wasm32-unknown-emscripten -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --sysroot=C:\Users\user\Downloads\emsdk\upstream\emscripten\cache\sysroot -DEMSCRIPTEN -Xclang -iwithsysroot/include\fakesdl -Xclang -iwithsysroot/include\compat -v -c main.cpp -o C:\Users\user\AppData\Local\Temp\emscripten_temp_qso33ae2\main_0.o' failed (returned 1)
#include <emscripten/bind.h>
#include <functional>

using namespace emscripten;

int add(int a, int b) {
    return a + b;
}

EMSCRIPTEN_BINDINGS(Example) {
    function("add", &add);
    function("add1", std::bind(&add, 1, std::placeholders::_1)); // error: no matching function for call to 'function'
}

This is propbably not intended to be used that way, but I've tried many other approaches and it seems like std::bind isn't supported. The question is: is there any way to use std::bind with Embind?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.