Re: SpiderMonkey38 as static lib on Windows
[email protected] Thu, 25 Aug 2016 06:05:03 -0700 (PDT)
| Newsgroups | gmane.comp.mozilla.devel.jseng |
|---|---|
| Message-ID | <[email protected]> |
On Thursday, August 25, 2016 at 2:03:12 PM UTC+2, Mihai Dobrescu wrote: > On Thursday, August 25, 2016 at 2:46:03 PM UTC+3, [email protected] wrote: > > On Thursday, August 25, 2016 at 12:14:50 PM UTC+2, Mihai Dobrescu wrote: > > > On Thursday, August 25, 2016 at 1:08:59 PM UTC+3, Mihai Dobrescu wrote: > > > > On Thursday, August 25, 2016 at 12:41:46 PM UTC+3, [email protected] wrote: > > > > > On Thursday, August 25, 2016 at 9:41:57 AM UTC+2, Mihai Dobrescu wrote: > > > > > > On Monday, August 22, 2016 at 11:42:14 PM UTC+3, [email protected] wrote: > > > > > > > On Monday, August 22, 2016 at 7:19:18 PM UTC+2, Mihai Dobrescu wrote: > > > > > > > > On Monday, August 22, 2016 at 7:09:53 PM UTC+3, [email protected] wrote: > > > > > > > > > Hi Guys, > > > > > > > > > > > > > > > > > > I'd like to use SpiderMonkey 38 on Windows as a static library. > > > > > > > > > > > > > > > > > > I have built x86 for Windows using the package published in this thread: > > > > > > > > > https://groups.google.com/forum/#!topic/mozilla.dev.tech.js-engine/1GC-7lkX-qk > > > > > > > > > Package: http://people.mozilla.org/~sfink/data/mozjs-38.3.0sfink2.tar.bz2 > > > > > > > > > > > > > > > > > > I can compile and link my own executables using mozjs-38.lib as: > > > > > > > > > > > > > > > > > > cl.exe /EHs /I"d:\spidermonkey38\js\src\build_OPT.OBJ\dist\include" /c helloworld.cpp > > > > > > > > > link.exe helloworld.obj "d:\spidermonkey38\js\src\build_OPT.OBJ\dist\lib\mozjs-38.lib" > > > > > > > > > > > > > > > > > > However, the below page suggests to use the "--disable-shared-js" flag for the configure script to build SpiderMonkey as a static lib: > > > > > > > > > https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Build_Documentation#Building_SpiderMonkey_as_a_static_library > > > > > > > > > > > > > > > > > > If I add this flag, then no mozjs-38.lib gets generated during mozmake. > > > > > > > > > Am I doing something wrong? Should I be using the "js_static.lib" to link my executable somehow? > > > > > > > > > > > > > > > > > > I'd appreciate any guidance! > > > > > > > > > > > > > > > > > > Thanks, > > > > > > > > > tamas > > > > > > > > > > > > > > > > Did you look in "build_OPT.OBJ\dist\sdk\lib"? > > > > > > > > > > > > > > > > > > > > > Yes, I just did, it's not there either. > > > > > > > > > > > > > > These files are there if I build without "--disable-shared-js" > > > > > > > mozjs-38.lib > > > > > > > nspr4.lib > > > > > > > nspr4.pdb > > > > > > > plc4.lib > > > > > > > plc4.pdb > > > > > > > plds4.lib > > > > > > > plds4.pdb > > > > > > > > > > > > > > .. but mozjs-38.lib is missing if I add the flag. > > > > > > > > > > > > To me, it looks like js.exe is created always with the static lib or it adds all the SpiderMonkey's code. > > > > > > > > > > > > IMHO, --disable-shared-js just skips the creation of the static lib. Anyway, I couldn't use the static lib itself, it gives me errors at linking. Did you manage to use it? > > > > > > > > > > Someone on IRC recommended to use the --disable-export-js flag as well additionally to --disable-shared-js, which two together makes STATIC_JS_API defined, but I cannot use the generated js_static.lib even after this. > > > > > > > > > > I dumpbed the symbols from js_static.lib, and it contains > > > > > ?JS_ShutDown@@YAXXZ (void __cdecl JS_ShutDown(void)) > > > > > > > > > > but the link error says: > > > > > helloworld.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl JS_ShutDown(void)" (__imp_?JS_ShutDown@@YAXXZ) referenced in function _main > > > > > > > > > > Note the __imp_ prefix in the error message. I really don't know what I'm missing.. > > > > > > > > Probably there is some flag to be added to your project in order to use the static lib mangling. > > > > > > What if you define STATIC_JS_API in your project too? > > > > I'm just trying to compile the helloworld example from here: > > https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/How_to_embed_the_JavaScript_engine#Hello_World_sample_embedding_application > > > > If I put [#define STATIC_JS_API] before the [#include "jsapi.h"] line, I get more unresolved symbol errors, for all the .obj files in js_static.lib as well. > > If I put it after [#include "jsapi.h"], it's the same. No success. > > In js\src\configure there is: > > > # Check whether --enable-shared-js or --disable-shared-js was given. > if test "${enable_shared_js+set}" = set; then > enableval="$enable_shared_js" > if test "$enableval" = "yes"; then > DISABLE_SHARED_JS=0 > elif test "$enableval" = "no"; then > DISABLE_SHARED_JS=1 > else > { echo "configure: error: Option, shared-js, does not take an argument ($enableval)." 1>&2; echo "configure: error: Option, shared-js, does not take an argument ($enableval)." 1>&5; exit 1; } > fi > fi > > > # Check whether --enable-export-js or --disable-export-js was given. > if test "${enable_export_js+set}" = set; then > enableval="$enable_export_js" > if test "$enableval" = "no"; then > DISABLE_EXPORT_JS=1 > elif test "$enableval" = "yes"; then > DISABLE_EXPORT_JS= > else > { echo "configure: error: Option, export-js, does not take an argument ($enableval)." 1>&2; echo "configure: error: Option, export-js, does not take an argument ($enableval)." 1>&5; exit 1; } > fi > fi > > > if test "$DISABLE_SHARED_JS" = "1" ; then > if test "$DISABLE_EXPORT_JS" = "1"; then > cat >> confdefs.pytmp <<\EOF > (''' STATIC_JS_API ''', ' 1 ') > EOF > cat >> confdefs.h <<\EOF > #define STATIC_JS_API 1 > EOF > > else > cat >> confdefs.pytmp <<\EOF > (''' STATIC_EXPORTABLE_JS_API ''', ' 1 ') > EOF > cat >> confdefs.h <<\EOF > #define STATIC_EXPORTABLE_JS_API 1 > EOF > > fi > else > if test "$DISABLE_EXPORT_JS" = "1"; then > { echo "configure: error: Must export JS symbols when building a shared library." 1>&2; echo "configure: error: Must export JS symbols when building a shared library." 1>&5; exit 1; } > fi > JS_SHARED_LIBRARY=1 > fi > > So, depending on your build, you watch for definition of one of STATIC_JS_API or STATIC_EXPORTABLE_JS_API in confdefs.h in your build directory tree (under \\js\src\build_OPT.OBJ\js\src, for example). > > Then, if is defined, do the same in your project, at project level, along with other symbols definitions for debug or release (where you have _DEBUG/NDEBUG etc., in the C++ preprocessor definitions section). In my case works this way. I am not using Visual Studio at the moment. I'm trying with: cl -c -I"d:\spidermonkey38\js\src\BUILD_OPT.OBJ\dist\include" helloworld.cpp and then link helloworld.obj "d:\spidermonkey38\js\src\BUILD_OPT.OBJ\dist\include" The shared version worked when configured WITHOUT --disable-shared-js and used mozjs-38.lib for linking, and the helloworld app worked using mozjs-38.dll I tried from Visual Studio, setting the project level #define and referencing js_static.lib for linking, but I get the exact same errors.