Domanda

I suspect this is a bone-headed newbie question, but it's one I cannot answer on my own.

I want to develop a program on Ubuntu 12.04 LTS (32-bit) with an embedded javascript engine. I've tried downloading SpiderMonkey but couldn't work out how to link against it. So, I've downloaded the V8 sources, which at least have an example program with linking instructions on the Google Developers site.

I've downloaded the sources and built in /some/path/or/other/v8 and have put the example source into v8Ex1 (I had hoped to move swiftly to examples 2, 3 and 4 - but no luck so far) in /some/path/or/other.

Once I worked out what to change for a 32-bit rather than 64-bit build, I was able to build and run the example using the command line

g++ -Iv8/include v8Ex1.cc -o v8Ex1 -Wl,--start-group v8/out/ia32.release/obj.target/{tools/gyp/libv8_{base.ia32,snapshot},third_party/icu/libicu{uc,i18n,data}}.a -Wl,--end-group -lrt

My next step was to determine how bash expanded that command line:

g++ -Iv8/include v8Ex1.cc -o v8Ex1 \
  -Wl,--start-group v8/out/ia32.release/obj.target/tools/gyp/libv8_base.ia32.a \
  v8/out/ia32.release/obj.target/tools/gyp/libv8_snapshot.a \
  v8/out/ia32.release/obj.target/third_party/icu/libicuuc.a \
  v8/out/ia32.release/obj.target/third_party/icu/libicui18n.a \
  v8/out/ia32.release/obj.target/third_party/icu/libicudata.a \
  -Wl,--end-group -lrt

This command works fine, building an executable without producing any errors or warnings.

I anticipate having multiple source files in my program, so I'll eventually have several object files and will need to link them together.

My next step was to construct separate compiler and linker commands

g++ -c -Iv8/include v8Ex1.cc -o v8Ex1.o

compiles the program just fine, but I haven't been able to work out what the corresponding linker command should be. My best guess is

ld -o v8Ex1 v8Ex1.o --start-group \
  v8/out/ia32.release/obj.target/tools/gyp/libv8_base.ia32.a \
  v8/out/ia32.release/obj.target/tools/gyp/libv8_snapshot.a \
  v8/out/ia32.release/obj.target/third_party/icu/libicuuc.a \
  v8/out/ia32.release/obj.target/third_party/icu/libicui18n.a \
  v8/out/ia32.release/obj.target/third_party/icu/libicudata.a --end-group -lrt

But this gives me 3257 errors, starting with the below:

/usr/bin/ld.bfd.real: warning: cannot find entry symbol _start; defaulting to 000000000804a2e0
v8Ex1.o: In function `main':
v8Ex1.cc:(.text+0x1ab): undefined reference to `_Unwind_Resume'
v8Ex1.o:(.eh_frame+0x4b): undefined reference to `__gxx_personality_v0'
v8/out/ia32.release/obj.target/v8_base.ia32/src/isolate.o: In function `v8::internal::DateCache::~DateCache()':
isolate.cc:(.text._ZN2v88internal9DateCacheD0Ev[_ZN2v88internal9DateCacheD5Ev]+0xb): undefined reference to `operator delete(void*)'
v8/out/ia32.release/obj.target/v8_base.ia32/src/isolate.o: In function `v8::internal::Isolate::FindOrAllocatePerThreadDataForThisThread()':
isolate.cc(.text._ZN2v88internal7Isolate40FindOrAllocatePerThreadDataForThisThreadEv+0x88): undefined reference to `operator new(unsigned int)'
v8/out/ia32.release/obj.target/v8_base.ia32/src/isolate.o: In function `v8::internal::Isolate::StackTraceString()':
isolate.cc:(.text._ZN2v88internal7Isolate16StackTraceStringEv+0x15a): undefined reference to `operator delete[](void*)'
v8/out/ia32.release/obj.target/v8_base.ia32/src/isolate.o: In function `v8::internal::Isolate::PrintStack(_IO_FILE*)':
isolate.cc:(.text._ZN2v88internal7Isolate10PrintStackEP8_IO_FILE+0x15f): undefined reference to `operator delete[](void*)'
isolate.cc:(.text._ZN2v88internal7Isolate10PrintStackEP8_IO_FILE+0x1f0): undefined reference to `operator new(unsigned int)'
isolate.cc:(.text._ZN2v88internal7Isolate10PrintStackEP8_IO_FILE+0x218): undefined reference to `operator new(unsigned int)'

Please can someone help me out with the correct linker command. I think I'll be able to wrap it into a Makefile OK on my own and then it'll be full speed ahead with my program.

È stato utile?

Soluzione

You haven't specified the linker errors you're seeing, so I can't help with that, but the following information may be helpful:

  1. If you have multiple source files, you can still compile/link them in one go:

    g++ -Iv8/include v8Ex1.cc othersource.cc othersource2.cc -o v8Ex1 \ 
      -Wl,--start-group v8/out/ia32.release/obj.target/tools/gyp/libv8_base.ia32.a \ 
      v8/out/ia32.release/obj.target/tools/gyp/libv8_snapshot.a \ 
      v8/out/ia32.release/obj.target/third_party/icu/libicuuc.a \ 
      v8/out/ia32.release/obj.target/third_party/icu/libicui18n.a \ 
      v8/out/ia32.release/obj.target/third_party/icu/libicudata.a \ 
      -Wl,--end-group -lrt
    
  2. If you want to compile them separately (e.g. to save time on incremental builds), you can link using g++ - just specify the .o files in place of the .c/.cc files:

    g++ -Iv8/include v8Ex1.o othersource.o othersource2.o -o v8Ex1 \
      -Wl,--start-group v8/out/ia32.release/obj.target/tools/gyp/libv8_base.ia32.a \
      v8/out/ia32.release/obj.target/tools/gyp/libv8_snapshot.a \
      v8/out/ia32.release/obj.target/third_party/icu/libicuuc.a \
      v8/out/ia32.release/obj.target/third_party/icu/libicui18n.a \
      v8/out/ia32.release/obj.target/third_party/icu/libicudata.a \
      -Wl,--end-group -lrt
    

This might save some wrestling with the arguments to ld.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top