2012-04-18 12 views
8

ठीक है, इसलिए मैंने wget http://ftp.mozilla.org/pub/mozilla.org/js/js185-1.0.0.tar.gz कमांड का उपयोग करके स्पाइडरमोन्की स्रोत कोड डाउनलोड किया और इसे निकाला।एम्बेडेड स्पाइडरमोन्की प्रोग्राम संकलित करते समय त्रुटि

  1. autoconf2.13
  2. ./configure --prefix=~/js --disable-shared-js
  3. make
  4. make install

अब मैं निम्नलिखित कोड का उपयोग कर संकलन की कोशिश की: तो फिर मैं सफलतापूर्वक फ़ाइलें और निम्न आदेशों को क्रियान्वित करने से स्थिर पुस्तकालय शामिल बनाया आदेश g++ -I/home/aaditmshah/js/include/js -L/home/aaditmshah/js/lib -lmozjs185-1.0 -ldl -lm -ldl helloworld.cpp -o helloworld:

/* 
* This define is for Windows only, it is a work-around for bug 661663. 
*/ 
#ifdef _MSC_VER 
# define XP_WIN 
#endif 

/* Include the JSAPI header file to get access to SpiderMonkey. */ 
#include "jsapi.h" 

/* The class of the global object. */ 
static JSClass global_class = { 
    "global", JSCLASS_GLOBAL_FLAGS, 
    JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, 
    JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, 
    JSCLASS_NO_OPTIONAL_MEMBERS 
}; 

/* The error reporter callback. */ 
void reportError(JSContext *cx, const char *message, JSErrorReport *report) 
{ 
    fprintf(stderr, "%s:%u:%s\n", 
      report->filename ? report->filename : "<no filename=\"filename\">", 
      (unsigned int) report->lineno, 
      message); 
} 

int main(int argc, const char *argv[]) 
{ 
    /* JSAPI variables. */ 
    JSRuntime *rt; 
    JSContext *cx; 
    JSObject *global; 

    /* Create a JS runtime. You always need at least one runtime per process. */ 
    rt = JS_NewRuntime(8 * 1024 * 1024); 
    if (rt == NULL) 
     return 1; 

    /* 
    * Create a context. You always need a context per thread. 
    * Note that this program is not multi-threaded. 
    */ 
    cx = JS_NewContext(rt, 8192); 
    if (cx == NULL) 
     return 1; 
    JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT); 
    JS_SetVersion(cx, JSVERSION_LATEST); 
    JS_SetErrorReporter(cx, reportError); 

    /* 
    * Create the global object in a new compartment. 
    * You always need a global object per context. 
    */ 
    global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL); 
    if (global == NULL) 
     return 1; 

    /* 
    * Populate the global object with the standard JavaScript 
    * function and object classes, such as Object, Array, Date. 
    */ 
    if (!JS_InitStandardClasses(cx, global)) 
     return 1; 

    /* Your application code here. This may include JSAPI calls 
    * to create your own custom JavaScript objects and to run scripts. 
    * 
    * The following example code creates a literal JavaScript script, 
    * evaluates it, and prints the result to stdout. 
    * 
    * Errors are conventionally saved in a JSBool variable named ok. 
    */ 
    char *script = "'Hello ' + 'World!'"; 
    jsval rval; 
    JSString *str; 
    JSBool ok; 
    const char *filename = "noname"; 
    uintN lineno = 0; 

    ok = JS_EvaluateScript(cx, global, script, strlen(script), 
          filename, lineno, &rval); 
    if (rval == NULL | rval == JS_FALSE) 
     return 1; 

    str = JS_ValueToString(cx, rval); 
    printf("%s\n", JS_EncodeString(cx, str)); 

    /* End of your application code */ 

    /* Clean things up and shut down SpiderMonkey. */ 
    JS_DestroyContext(cx); 
    JS_DestroyRuntime(rt); 
    JS_ShutDown(); 
    return 0; 
} 

मुझे पता है कि मेरे include और linker विकल्प सही निर्देशिकाओं को इंगित करते हैं। फाइलें /home/aaditmshah/js/include/js में हैं और libmozjs185-1.0 नामक स्थिर लाइब्रेरी /home/aaditmshah/js/lib में है। हालांकि यह अभी भी निम्न त्रुटि पैदा करता है:

helloworld.cpp: In function ‘int main(int, const char**)’: 
helloworld.cpp:74:20: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings] 
helloworld.cpp:83:17: warning: NULL used in arithmetic [-Wpointer-arith] 
/tmp/ccUU9may.o: In function `main': 
helloworld.cpp:(.text+0x6e): undefined reference to `JS_Init' 
helloworld.cpp:(.text+0x94): undefined reference to `JS_NewContext' 
helloworld.cpp:(.text+0xba): undefined reference to `JS_SetOptions' 
helloworld.cpp:(.text+0xcb): undefined reference to `JS_SetVersion' 
helloworld.cpp:(.text+0xdc): undefined reference to `JS_SetErrorReporter' 
helloworld.cpp:(.text+0xf2): undefined reference to `JS_NewCompartmentAndGlobalObject' 
helloworld.cpp:(.text+0x11a): undefined reference to `JS_InitStandardClasses' 
helloworld.cpp:(.text+0x191): undefined reference to `JS_EvaluateScript' 
helloworld.cpp:(.text+0x1c8): undefined reference to `JS_ValueToString' 
helloworld.cpp:(.text+0x1df): undefined reference to `JS_EncodeString' 
helloworld.cpp:(.text+0x1f3): undefined reference to `JS_DestroyContext' 
helloworld.cpp:(.text+0x1ff): undefined reference to `JS_Finish' 
helloworld.cpp:(.text+0x204): undefined reference to `JS_ShutDown' 
/tmp/ccUU9may.o:(.data+0x10): undefined reference to `JS_PropertyStub' 
/tmp/ccUU9may.o:(.data+0x18): undefined reference to `JS_PropertyStub' 
/tmp/ccUU9may.o:(.data+0x20): undefined reference to `JS_PropertyStub' 
/tmp/ccUU9may.o:(.data+0x28): undefined reference to `JS_StrictPropertyStub' 
/tmp/ccUU9may.o:(.data+0x30): undefined reference to `JS_EnumerateStub' 
/tmp/ccUU9may.o:(.data+0x38): undefined reference to `JS_ResolveStub' 
/tmp/ccUU9may.o:(.data+0x40): undefined reference to `JS_ConvertStub' 
/tmp/ccUU9may.o:(.data+0x48): undefined reference to `JS_FinalizeStub' 
collect2: ld returned 1 exit status 

मुझे आश्चर्य है कि कौन-सी फ़ाइलें मुझे याद आ रही। क्या मुझे स्पाइडरमोन्की का पुनर्निर्माण करना चाहिए और इसे /usr/local में स्थापित करना चाहिए? किसी भी प्रकार की सहायता सराहनीय होगी।

मुझे पूरा यकीन है कि समस्या यह नहीं है कि मैं एक स्थिर पुस्तकालय का उपयोग कर रहा हूं। मैंने स्पाइडरमोन्की को एक साझा ऑब्जेक्ट लाइब्रेरी के रूप में पुनर्निर्मित किया और यह अभी भी मुझे एक ही त्रुटि देता है।

+1

मुझे यह कहना वास्तव में खेद है, लेकिन यह मेरे लिए ठीक काम करता है। मुझे दोनों सी ++ चेतावनियां मिलती हैं, लेकिन कोई लिंकर त्रुटियां नहीं होती हैं। परिणामी निष्पादन योग्य ठीक चलाता है। मैं मैक पर हूँ आप 'nm libmozjs185-1.0.a | के आउटपुट को देखना चाहेंगे grep JS_NewContext'। मुझे एक पंक्ति मिलती है जो '00000000000016d0 टी _JS_NewContext' कहती है। –

+0

मुझे एक पंक्ति मिलती है जो '0000000000003500 टी JS_NewContext' कहती है, जिसका मुझे लगता है कि 'JS_NewContext'' 13568' का मान है। मुझे यकीन नहीं है कि इस आउटपुट को क्या करना है। –

उत्तर

1

आप इस कोशिश कर सकते हैं:

g++ -I/home/aaditmshah/js/include/js /home/aaditmshah/js/lib/mozjs185-1.0.a -lm -ldl helloworld.cpp -o helloworld 

अर्थात्। सीधे g ++ कमांड लाइन में संग्रह जोड़ें। यदि यह काम नहीं कर रहा है तो आपको इनमें से कुछ संयोजन निर्दिष्ट करने की आवश्यकता हो सकती है। (जीसीसी 4.2 के साथ यह मेरे लिए काम किया):

-static -lmozjs185 

बस mozjs185-1.0.a के लिए सही पथ निर्दिष्ट करें।

+0

नहीं, यह अभी भी काम नहीं करता है। '-lm' और 'ldld' विकल्पों का क्या अर्थ है? मैं जी ++ संस्करण 'जी ++ - 4.6.real (उबंटू/लिनारो 4.6.1-9ubuntu3) 4.6.1' का उपयोग कर रहा हूं। –

0

उबंटू 12.10 पर, जी ++ संस्करण जीसीसी संस्करण 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1) और SipderMonkey v1.8.5: आदेश sudo g++ -o helloworld -I /usr/local/include/js helloworld.cpp -lmozjs185-1.0 -L /usr/local/lib -lpthread इतना आसान आह कुछ कर उम्मीद समय की तुलना में अधिक खर्च है! फ़ायरफ़ॉक्स/मोज़िला के लिए कोई धन्यवाद नहीं।

संबंधित मुद्दे