Skip to content

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

Closed
@GarasChan

Description

@GarasChan

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions