How to fix undefined reference to v8 error?
<p>I'm trying to configure and build a sample of node.js addon. The sample was taken from node.js documentation and the source code can be found here</p>

<p><a href="https://github.com/nodejs/node-addon-examples/tree/master/8_passing_wrapped/node_0.12" rel="nofollow">https://github.com/nodejs/node-addon-examples/tree/master/8_passing_wrapped/node_0.12</a></p>

<p>When I try to compile this in CLion (on Ubuntu 14.04) or when I use node-gyp to build it I've got some errors:</p>

<pre><code>    /home/smorzhov/Documents/clion-2016.1/bin/cmake/bin/cmake --build /home/smorzhov/.CLion2016.1/system/cmake/generated/test4-94ee4803/94ee4803/Debug --target all -- -j 4
[ 25%] Linking CXX executable test4
CMakeFiles/test4.dir/myobject.cpp.o: In function `demo::MyObject::Init(v8::Isolate*)':
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:26: undefined reference to `v8::FunctionTemplate::New(v8::Isolate*, void (*)(v8::FunctionCallbackInfo&lt;v8::Value&gt; const&amp;), v8::Local&lt;v8::Value&gt;, v8::Local&lt;v8::Signature&gt;, int)'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:27: undefined reference to `v8::String::NewFromUtf8(v8::Isolate*, char const*, v8::String::NewStringType, int)'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:27: undefined reference to `v8::FunctionTemplate::SetClassName(v8::Local&lt;v8::String&gt;)'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:28: undefined reference to `v8::FunctionTemplate::InstanceTemplate()'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:28: undefined reference to `v8::ObjectTemplate::SetInternalFieldCount(int)'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:30: undefined reference to `v8::FunctionTemplate::GetFunction()'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:30: undefined reference to `demo::MyObject::constructor'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase&lt;v8::Function&gt;::Reset()':
/usr/include/node/v8.h:7224: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase&lt;v8::Function&gt;::New(v8::Isolate*, v8::Function*)':
/usr/include/node/v8.h:7176: undefined reference to `v8::V8::GlobalizeReference(v8::internal::Isolate*, v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `Reset&lt;v8::Function&gt;':
/usr/include/node/v8.h:7235: undefined reference to `demo::MyObject::constructor'
CMakeFiles/test4.dir/myobject.cpp.o: In function `demo::MyObject::New(v8::FunctionCallbackInfo&lt;v8::Value&gt; const&amp;)':
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:38: undefined reference to `v8::Value::NumberValue() const'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local&lt;v8::Function&gt;::New(v8::Isolate*, v8::PersistentBase&lt;v8::Function&gt; const&amp;)':
/usr/include/node/v8.h:7124: undefined reference to `demo::MyObject::constructor'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local&lt;v8::Function&gt;::New(v8::Isolate*, v8::Function*)':
/usr/include/node/v8.h:7134: undefined reference to `v8::HandleScope::CreateHandle(v8::internal::Isolate*, v8::internal::Object*)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `demo::MyObject::New(v8::FunctionCallbackInfo&lt;v8::Value&gt; const&amp;)':
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:47: undefined reference to `v8::Function::NewInstance(int, v8::Local&lt;v8::Value&gt;*) const'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local&lt;v8::Function&gt;::New(v8::Isolate*, v8::PersistentBase&lt;v8::Function&gt; const&amp;)':
/usr/include/node/v8.h:7124: undefined reference to `demo::MyObject::constructor'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local&lt;v8::Function&gt;::New(v8::Isolate*, v8::Function*)':
/usr/include/node/v8.h:7134: undefined reference to `v8::HandleScope::CreateHandle(v8::internal::Isolate*, v8::internal::Object*)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `demo::MyObject::NewInstance(v8::FunctionCallbackInfo&lt;v8::Value&gt; const&amp;)':
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:57: undefined reference to `v8::Function::NewInstance(int, v8::Local&lt;v8::Value&gt;*) const'
CMakeFiles/test4.dir/myobject.cpp.o: In function `ClearWeak&lt;void&gt;':
/usr/include/node/v8.h:7298: undefined reference to `v8::V8::ClearWeak(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase&lt;v8::Object&gt;::Reset()':
/usr/include/node/v8.h:7224: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `node::ObjectWrap::Wrap(v8::Local&lt;v8::Object&gt;)':
/usr/include/node/node_object_wrap.h:56: undefined reference to `v8::Object::InternalFieldCount()'
/usr/include/node/node_object_wrap.h:57: undefined reference to `v8::Object::SetAlignedPointerInInternalField(int, void*)'
/usr/include/node/node_object_wrap.h:58: undefined reference to `v8::Isolate::GetCurrent()'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase&lt;v8::Object&gt;::Reset()':
/usr/include/node/v8.h:7224: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase&lt;v8::Object&gt;::New(v8::Isolate*, v8::Object*)':
/usr/include/node/v8.h:7176: undefined reference to `v8::V8::GlobalizeReference(v8::internal::Isolate*, v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `SetWeak&lt;v8::Object, node::ObjectWrap&gt;':
/usr/include/node/v8.h:7257: undefined reference to `v8::V8::MakeWeak(v8::internal::Object**, void*, void (*)(v8::WeakCallbackData&lt;v8::Value, void&gt; const&amp;))'
CMakeFiles/test4.dir/myobject.cpp.o: In function `ClearWeak&lt;void&gt;':
/usr/include/node/v8.h:7298: undefined reference to `v8::V8::ClearWeak(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `node::ObjectWrap::WeakCallback(v8::WeakCallbackData&lt;v8::Object, node::ObjectWrap&gt; const&amp;)':
/usr/include/node/node_object_wrap.h:101: undefined reference to `v8::HandleScope::HandleScope(v8::Isolate*)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local&lt;v8::Object&gt;::New(v8::Isolate*, v8::Object*)':
/usr/include/node/v8.h:7134: undefined reference to `v8::HandleScope::CreateHandle(v8::internal::Isolate*, v8::internal::Object*)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase&lt;v8::Object&gt;::Reset()':
/usr/include/node/v8.h:7224: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `node::ObjectWrap::WeakCallback(v8::WeakCallbackData&lt;v8::Object, node::ObjectWrap&gt; const&amp;)':
/usr/include/node/node_object_wrap.h:108: undefined reference to `v8::HandleScope::~HandleScope()'
/usr/include/node/node_object_wrap.h:108: undefined reference to `v8::HandleScope::~HandleScope()'
CMakeFiles/test4.dir/addon.cpp.o: In function `demo::Add(v8::FunctionCallbackInfo&lt;v8::Value&gt; const&amp;)':
/home/smorzhov/ClionProjects/test4/test4/addon.cpp:27: undefined reference to `v8::Number::New(v8::Isolate*, double)'
CMakeFiles/test4.dir/addon.cpp.o: In function `demo::InitAll(v8::Local&lt;v8::Object&gt;)':
/home/smorzhov/ClionProjects/test4/test4/addon.cpp:31: undefined reference to `v8::Object::GetIsolate()'
CMakeFiles/test4.dir/addon.cpp.o: In function `_register_addon':
/home/smorzhov/ClionProjects/test4/test4/addon.cpp:37: undefined reference to `node_module_register'
CMakeFiles/test4.dir/addon.cpp.o: In function `v8::Value::ToObject() const':
/usr/include/node/v8.h:7778: undefined reference to `v8::Isolate::GetCurrent()'
/usr/include/node/v8.h:7778: undefined reference to `v8::Isolate::GetCurrentContext()'
/usr/include/node/v8.h:7779: undefined reference to `v8::Value::ToObject(v8::Local&lt;v8::Context&gt;) const'
CMakeFiles/test4.dir/addon.cpp.o: In function `demo::MyObject* node::ObjectWrap::Unwrap&lt;demo::MyObject&gt;(v8::Local&lt;v8::Object&gt;)':
/usr/include/node/node_object_wrap.h:29: undefined reference to `v8::Object::InternalFieldCount()'
CMakeFiles/test4.dir/addon.cpp.o: In function `v8::Object::GetAlignedPointerFromInternalField(int)':
/usr/include/node/v8.h:7636: undefined reference to `v8::Object::SlowGetAlignedPointerFromInternalField(int)'
CMakeFiles/test4.dir/addon.cpp.o: In function `void node::NODE_SET_METHOD&lt;v8::Local&lt;v8::Object&gt; &gt;(v8::Local&lt;v8::Object&gt; const&amp;, char const*, void (*)(v8::FunctionCallbackInfo&lt;v8::Value&gt; const&amp;))':
/usr/include/node/node.h:239: undefined reference to `v8::Isolate::GetCurrent()'
/usr/include/node/node.h:240: undefined reference to `v8::HandleScope::HandleScope(v8::Isolate*)'
/usr/include/node/node.h:242: undefined reference to `v8::FunctionTemplate::New(v8::Isolate*, void (*)(v8::FunctionCallbackInfo&lt;v8::Value&gt; const&amp;), v8::Local&lt;v8::Value&gt;, v8::Local&lt;v8::Signature&gt;, int)'
/usr/include/node/node.h:243: undefined reference to `v8::FunctionTemplate::GetFunction()'
/usr/include/node/node.h:244: undefined reference to `v8::String::NewFromUtf8(v8::Isolate*, char const*, v8::String::NewStringType, int)'
/usr/include/node/node.h:245: undefined reference to `v8::Function::SetName(v8::Local&lt;v8::String&gt;)'
/usr/include/node/node.h:246: undefined reference to `v8::Object::Set(v8::Local&lt;v8::Value&gt;, v8::Local&lt;v8::Value&gt;)'
/usr/include/node/node.h:246: undefined reference to `v8::HandleScope::~HandleScope()'
/usr/include/node/node.h:246: undefined reference to `v8::HandleScope::~HandleScope()'
collect2: error: ld returned 1 exit status
make[2]: *** [test4] Error 1
make[1]: *** [CMakeFiles/test4.dir/all] Error 2
make: *** [all] Error 2
</code></pre>

<p>Maybe it is important, the IDE don't understand 

    <code>#include node.h </code> 

and I have to change it to <code>#include node/node.h</code></p>

<p>It seems, that compiler sees only node and v8 headers and cannot find their sources.</p>

<p>Can somebody help me to fix that? How to make compiler to see node and v8 sources?</p>

<p>PS. My CmakeLists.txt file</p>

<pre><code>cmake_minimum_required(VERSION 3.3)
project(test4)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES addon.cpp main.cpp myobject.cpp myobject.h)
add_executable(test4 ${SOURCE_FILES})
</code></pre>