Steps to reproduce:
*Main.cpp:*
static void (*g_pFunc)() = 0;
void Register(void (*pFunc)())
{
g_pFunc = pFunc;
}
int main()
{
if (g_pFunc)
g_pFunc();
return 0;
}
*Lib.cpp:*
#include <stdio.h>
extern void Register(void (*pFunc)());
static void PrintFunc()
{
printf("Hello from lib\n");
}
struct CRegistrator
{
CRegistrator()
{
Register(&PrintFunc);
}
};
static CRegistrator g_Registrator;
*Compile with Emscripten:*
em++ -c -o Lib.o Lib.cpp
emar rcs libLib.a Lib.o
em++ Main.cpp -Wl,--whole-archive libLib.a -Wl,--no-whole-archive -o a.html
*a.html should print "Hello from lib", but it doesn't.*
*Compile with GCC:*
g++ -c -o Lib.o Lib.cpp
ar rcs libLib.a Lib.o
g++ Main.cpp -Wl,--whole-archive libLib.a -Wl,--no-whole-archive -o a.out
*a.out prints "Hello from lib" as expected.*
Hi!
>
> I need to link an executable against a static library which is using only
> static variables for its registration (this is actually a plugin).
>
> Usually -force_load (for Clang) or --whole-archive (for GCC) are used to
> force a library to link. But it seems link Emscripten just ignores these
> flags.
>
> Any advice?
>
> Andrew.
>
--
You received this message because you are subscribed to the Google Groups
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.