help icon indicating copy to clipboard operation
help copied to clipboard

Embedder Linker Error

Open schuetzenhofer opened this issue 3 years ago • 0 comments

Details

We're trying to embed Node.js into a simple C++ application following this guide ### https://nodejs.org/api/embedding.html.

Downloaded the Source Code and built it successfully using

./configure
 make -j4

Then wrote a simple Cmake that links to all (29) static libraries in out/Release

cmake_minimum_required(VERSION 3.23)

project(v8-cpp)
set(CMAKE_CXX_STANDARD 20)

set(NODE_DIR ${CMAKE_SOURCE_DIR}/node)

set(HEADERS

)

set(SOURCES

)

set(INCLUDE_DIRS
 ${NODE_DIR}/deps/v8/include/
 ${NODE_DIR}/deps/uv/include/

 ${NODE_DIR}/src/
)

add_executable(${PROJECT_NAME}
 main.cpp
 ${HEADERS}
 ${SOURCES}
)

target_link_libraries(${PROJECT_NAME}    
 ${NODE_DIR}/out/Release/libzlib.a
 ${NODE_DIR}/out/Release/libbase64_neon64.a
 ${NODE_DIR}/out/Release/libbase64.a
 ${NODE_DIR}/out/Release/libbrotli.a
 ${NODE_DIR}/out/Release/libcares.a
 ${NODE_DIR}/out/Release/libgtest_main.a
 ${NODE_DIR}/out/Release/libgtest.a
 ${NODE_DIR}/out/Release/libhistogram.a
 ${NODE_DIR}/out/Release/libicudata.a
 ${NODE_DIR}/out/Release/libicui18n.a
 ${NODE_DIR}/out/Release/libicutools.a
 ${NODE_DIR}/out/Release/libicuucx.a
 ${NODE_DIR}/out/Release/libllhttp.a
 ${NODE_DIR}/out/Release/libnghttp2.a
 ${NODE_DIR}/out/Release/libnghttp3.a
 ${NODE_DIR}/out/Release/libngtcp2.a
 ${NODE_DIR}/out/Release/libnode.a
 ${NODE_DIR}/out/Release/libopenssl.a
 ${NODE_DIR}/out/Release/libtorque_base.a
 ${NODE_DIR}/out/Release/libuv.a
 ${NODE_DIR}/out/Release/libuvwasi.a
 ${NODE_DIR}/out/Release/libv8_base_without_compiler.a
 ${NODE_DIR}/out/Release/libv8_compiler.a
 ${NODE_DIR}/out/Release/libv8_init.a
 ${NODE_DIR}/out/Release/libv8_initializers.a
 ${NODE_DIR}/out/Release/libv8_libbase.a
 ${NODE_DIR}/out/Release/libv8_libplatform.a
 ${NODE_DIR}/out/Release/libv8_snapshot.a
 ${NODE_DIR}/out/Release/libv8_zlib.a
)

target_include_directories(${PROJECT_NAME} PUBLIC
 ${INCLUDE_DIRS}
)

Using the exact code from the guide yields this error

Undefined symbols for architecture arm64:
"node::SnapshotBuilder::GetEmbeddedSnapshotData()", referenced from:
node::GenerateAndWriteSnapshotData(node::SnapshotData const*, node::InitializationResult const) in libnode.a(node.o)
node::LoadSnapshotDataAndRun(node::SnapshotData const*, node::InitializationResult const) in libnode.a(node.o)
node::worker::Worker::New(v8::FunctionCallbackInfo<v8::Value> const&) in libnode.a(node_worker.o)
node::contextify::ContextifyContext::ContextifyContext(node::Environment*, v8::Local<v8::Object>, node::contextify::ContextOptions const&) in libnode.a(node_contextify.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Undefined symbol: node::SnapshotBuilder::GetEmbeddedSnapshotData()

We tried building with --without-node-snapshot but are still getting the same error. We also tried with version 16.17.0, but are getting the same error and two other ones.

Node.js version

v18.8.0

Example code

No response

Operating system

MacOS Monterey (M1)

Scope

Intallation / Linking

Module and version

Embedder

schuetzenhofer avatar Sep 01 '22 11:09 schuetzenhofer