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.
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 caselibv8-dev
which needs to be installed.You then need the line:
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.