-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
undefined reference linking errors during cross-compilation (using cmake-js) #1021
Comments
Hi @sakthi-vivek, In some projects I used the library stub of Node-API that you can downlod from here: https://github.com/napi-bindings/node-api-stub/releases The CMake file that I sued is like the following: cmake_minimum_required(VERSION 3.16)
cmake_policy(SET CMP0042 NEW)
project(addon)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_NODE_API_LIB libnode.a)
include_directories(${CMAKE_SOURCE_DIR}/include)
set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/addon.cc
)
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
target_link_libraries(${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/lib/${CMAKE_NODE_API_LIB})
# Define NAPI_VERSION
add_definitions(-DNAPI_VERSION=3) I put the library stub in the lib folder and the include Node-API header files in the include folder. You can find the Node-API headers file in this repo: https://github.com/nodejs/node-api-headers. In my case I compiled and built the addon directly from WIndows using the following command: cmake.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:/TDM-GCC-64/bin/mingw32-make.exe -DCMAKE_C_COMPILER=C:/TDM-GCC-64/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/TDM-GCC-64/bin/g++.exe -G "CodeBlocks - MinGW Makefiles" I hope that the these info could help you. |
@NickNaso Thank you for the reply. I managed to cross-compile for Windows from Linux, thanks to your node-api-stub. However I am getting a I am closing this issue, but could you please share any tips that we should be aware of when we are using the stub library? For more context, I am using the resultant node artifact in an electron application. Thank you again for the help :) |
Hi @sakthi-vivek, #include <node_api.h>
#include "addon.h"
extern "C" {
extern __declspec(dllexport) napi_value napi_register_module_v1(napi_env env, napi_value exports) {
return Initialize(env, exports);
}
} I hope that this works for you. |
Thank you @NickNaso, May I ask where exactly is I have also discovered that the |
Hi @sakthi-vivek, |
Hello,
In order to demonstrate this issue, I used this example https://github.com/nodejs/node-addon-examples/tree/main/build_with_cmake/node-addon-api.
After running npm installtion (cmake-js was globally installed), I was able to successfully create node modules for the linux with just a
cmake-js compile
. I then attempted a cross-compilation for Windows using mingw-w64 (x86_64-w64-mingw32-g++ (GCC) 8.3-posix 20190406
- used the non-default posix sincestd::mutex
used by napi was not supported by the default cross-compiler).cmake-js compile --CDCMAKE_CXX_COMPILER="/usr/bin/x86_64-w64-mingw32-g++"
However, I get the following output which states that compilation failed due to a lot of undefined references at the linking step.
Thank you for any help.
The text was updated successfully, but these errors were encountered: