Skip to content

How can I create a variable share between MAIN_MODULE and SIDE_MODULE so that SIDE_MODULE can access it when initializing? #22694

Closed Answered by oatgnauh
ruiqurm asked this question in Q&A
Discussion options

You must be logged in to vote

you can try this way, passing the address to Module for proxy, using more cpp style, dude
a.cpp

#include <dlfcn.h>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <emscripten.h>

typedef void (*func_t)();
static std::map<std::string, func_t> register_map;

int main()
{
  printf("hello world,addr of `register_map`=%p\n",&register_map);
  // make sure using in the same thread
  EM_ASM({
      if(!Module["register_map"]) {
          Module["register_map"] = $0;
      } 
 }, &register_map);

  std::cout << "before loading" << std::endl;
  std::cout << register_map["hello"] << std::endl;
  std::cout << register_map["world"] << std::endl;
  void *handle = dlopen("

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@ruiqurm
Comment options

@oatgnauh
Comment options

Comment options

You must be logged in to vote
3 replies
@ruiqurm
Comment options

@oatgnauh
Comment options

@ruiqurm
Comment options

Answer selected by ruiqurm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants