Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After c++ is compiled into wasm, the internal methods are not found and need to be imported by “imports” #7389

Closed
GarasChan opened this issue Oct 25, 2018 · 6 comments

Comments

@GarasChan
Copy link

C++ Code:

#include <iostream>
using namespace std;

extern "C" {
    void ReadHead(char *path)
    {
        if ((m_ShpFile_fp = fopen(path, "rb")) == NULL)
        {
            return;
        }
        fread(&file_Head.FileCode, sizeof(int), 1, m_ShpFile_fp);
        fread(&file_Head.FileLength, sizeof(int), 1, m_ShpFile_fp);
        file_Head.FileLength = OnChangeByteOrder(file_Head.FileLength);
        fread(&file_Head.ShapeType, sizeof(int), 1, m_ShpFile_fp);
        ...
    }
}

here, the functions "fopen" and "fread" can not be found。

emcc:
emcc shp.cpp -Os -s WASM=1 -s SIDE_MODULE=1 -o shp.wasm

wasm file:

...
(import "env" "_fopen" (func $env._fopen (type $t0)))
(import "env" "_fread" (func $env._fread (type $t8)))
...

Error:

Here are some of the errors listed. I think it may be that emcc compiles without introducing the required lib, which is the header file (.h).

@kripken
Copy link
Member

kripken commented Oct 25, 2018

In a side module, system libraries are not linked in, so it calls out to things like fopen etc. And then you need to provide them as imports. (A main module will provide them to the side module; if you load the module yourself, you need to handle it.)

@GarasChan
Copy link
Author

Thank you very much for your reply. And how to import the required resources? @kripken

@kripken
Copy link
Member

kripken commented Oct 26, 2018

You can look at a main module to see how it does it (compile it, run it to see that it works, then look at the code). There isn't much more in terms of docs for this - some of it is the normal libc API, some is internal APIs.

@GarasChan
Copy link
Author

Where is the main module, and how to find it? @kripken

@kripken
Copy link
Member

kripken commented Oct 26, 2018

@GarasChan
Copy link
Author

Thanks for your help very much, and I will close this case. @kripken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants