kripken/emscripten — Issue #258: Function Names Are Lost with -O2 or -O3
Author: peterleecomcn
Created: 2012-02-16 23:27:49+00:00
State: open

The following source code in `main.cpp`:

```c++
class Complex
{
public:
Complex(int x, int y)
:x(x), y(y)
{

}

double GetLengthSquared()
{
return x*x + y*y;
}

private:
double x;
double y;
};

extern "C"
{

#include
#include

double Complex_GetLengthSquared(Complex* pc)
{
return pc->GetLengthSquared();
}

char* GetData(int* size)
{
const char* cs = "A Const Char String";
*size = strlen(cs);

return (char*)cs;
}

}

int main(int argc, char* argv[])
{
int size = 0;
char* data = GetData(&size);
printf("%s: %d\n", data, size);

Complex c(1, 2);
printf("%lf\n", Complex_GetLengthSquared(&c));

return 0;
}
```

With `-O1` optimization:
```
emcc -O1 main.cpp -o main.js
```

I could still find two function names:
```
_GetData
_Complex_GetLengthSquared
```

But with `-O2` or `-O3`
```
emcc -O2 main.cpp -o main.js
```

In `main.js`, I cannot find any useful function names? How can interact with the compiled code?

Thanks.