0

I was trying to use the libv8-3.8.9.20 package in my c++ script. The package is installed in /usr/lib/ as supposed but if I try to compile my script using g++ script.cpp -Iv8 command, nothing happens.

What should be in the script's header so I could use the library? This is what I've tried:

#include <v8>
#include <libv8>
#include <libv8.so>
#include <v8.so>

On the next line was using namespace v8 command. When I do this, g++ returns an error:

index.cpp:1:20: fatal error: libv8.so: No such file or directory
 #include <libv8.so>
                    ^
compilation terminated.

Or something like that. I have even tried to compile it without the header but g++ didn't like it.

Is it possible to use the library this way? And how? Thank you, m93a

EDIT: After installing libv8-dev (or libv8-3.14-dev, I've tried both) compiler throws:

index.cpp: In function ‘int main(int, char**)’:
index.cpp:10:35: error: no matching function for call to ‘v8::HandleScope::HandleScope(v8::Isolate*&)’
   HandleScope handle_scope(isolate);
                                   ^
index.cpp:10:35: note: candidates are:
In file included from index.cpp:1:0:
/usr/include/v8.h:473:3: note: v8::HandleScope::HandleScope(const v8::HandleScope&)
   HandleScope(const HandleScope&);
   ^

And so on... (it's too long and still saying something's not found)
I'm using g++ main.cpp -lv8 command.

1
  • Could add you main.cpp code to the question? if you still have it, now 6years ago.
    – user.dz
    Nov 3, 2019 at 10:56

1 Answer 1

3

To use a library in a program you are writing (in C/C++ at least), you need not only the compiled library (the .so - shared object file) but also a header file, which describes the functions and data structures used by the library.

Header files are not usually installed by default. They are usually found in a package called libwhatever-dev, in this case libv8-dev which needs to be installed.

You then need the line:

#include <v8.h>

to include the V8 headers. When compiling, you'll also need to tell g++ to link with the v8 library (-lv8). V8 is a fairly complex beast, and it would probably be wise to find a working example or tutorial to see how they compile it.

Finally, a note on terminology: a script normally refers to code which is executed directly from the readable text form by an interpreter (such as python), whereas this has to be first compiled before it can be run.

1
  • Thanks for your help! Yeah, that -Iv8 was my fault. I've tried your solution - still not working - details at the bottom of my question. PS: If it's not a script, what is it? Just code?
    – m93a
    Nov 18, 2013 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .