Closed aminya closed 3 years ago
I am testing this on Zadeh here: https://github.com/atom-community/zadeh/tree/cmake-ts
The build fails with a missing symbol error (undefined symbol: _DllMainCRTStartup
).
config
"cmake-ts": {
"nodeAPI": "node-addon-api",
"configurations": [
{
"os": "win32",
"arch": "x64",
"runtime": "node",
"runtimeVersion": "16.0.0"
}
],
"targetDirectory": "build",
"buildType": "Release",
"projectName": "zadeh"
},
Cmake
cmake_minimum_required(VERSION 3.17)
project(zadeh VERSION "2.0.2" LANGUAGES CXX)
# Source files
file(GLOB SOURCE_FILES "./src")
# .node file target
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
# Include paths
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INCL})
# Language and standard
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
Error
❯ .\node_modules\.bin\cmake-ts
no generator specified, checking ninja
found ninja at C:\ProgramData\chocolatey\bin\ninja.EXE
running in C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\zadeh command [
'C:\\Program Files\\nodejs\\node.exe',
'C:\\Users\\aminy\\Documents\\GitHub\\JavaScript\\@atom-ide-community\\zadeh\\node_modules\\cmake-ts\\build\\main.js'
]
> Setting up staging directory... [ CLEARED ][ DONE ]
---------------- BEGIN CONFIG ----------------
> Distribution File Download... [ DONE ]
> Determining ABI... [ DONE ]
> Building directories... [ DONE ]
--------------- CONFIG SUMMARY ---------------
OS/Arch: win32 x64
Runtime: node 16.0.0
Target ABI: 93
Toolchain File: null
Custom options: no
Staging area: C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\zadeh\staging\win32\x64\node\93
Target directory: C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\zadeh\build\win32\x64\node\93
Build Type Release
----------------------------------------------
> Setting up config specific staging directory... [ DONE ]
> Building CMake command line... [ DONE ]
-- Build files have been written to: C:/Users/aminy/Documents/GitHub/JavaScript/@atom-ide-community/zadeh/staging/win32/x64/node/93
[ DONE ]
[1/1] Linking CXX shared library zadeh.node
FAILED: zadeh.node zadeh.lib
cmd.exe /C "cd . && C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE -fuse-ld=lld-link -nostartfiles -nostdlib -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -shared -o zad
eh.node -Xlinker /implib:zadeh.lib -Xlinker /pdb:zadeh.pdb -Xlinker /version:0.0 C:/Users/aminy/.cmake-ts/node/win32/x64/v16.0.0/win-x64/node.lib -lkernel32 -luser32
-lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ."
lld-link: warning: /machine is not specified. x64 is assumed
lld-link: error: <root>: undefined symbol: _DllMainCRTStartup
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Generic error occured Error: Process terminated: 1
at ChildProcess.<anonymous> (C:\Users\aminy\Documents\GitHub\JavaScript\cmake-ts\build\util.js:99:24)
at ChildProcess.emit (node:events:365:28)
at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
I changed the linker language from C++ to C, and Cmake builds, but .node
file is not generated:
cmake_minimum_required(VERSION 3.17)
project(zadeh VERSION "2.0.2" LANGUAGES CXX)
# Source files
file(GLOB SOURCE_FILES "./src")
# .node file target
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C)
# linking libs
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
# Include paths
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC})
Error:
❯ .\node_modules\.bin\cmake-ts
no generator specified, checking ninja
found ninja at C:\ProgramData\chocolatey\bin\ninja.EXE
running in C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\zadeh command [
'C:\\Program Files\\nodejs\\node.exe',
'C:\\Users\\aminy\\Documents\\GitHub\\JavaScript\\@atom-ide-community\\zadeh\\node_modules\\cmake-ts\\build\\main.js'
]
> Setting up staging directory... [ CLEARED ][ DONE ]
---------------- BEGIN CONFIG ----------------
> Distribution File Download... [ DONE ]
> Determining ABI... [ DONE ]
> Building directories... [ DONE ]
--------------- CONFIG SUMMARY ---------------
OS/Arch: win32 x64
Runtime: node 16.0.0
Target ABI: 93
Toolchain File: null
Custom options: no
Staging area: C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\zadeh\staging\win32\x64\node\93
Target directory: C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\zadeh\build\win32\x64\node\93
Build Type Release
----------------------------------------------
> Setting up config specific staging directory... [ DONE ]
> Building CMake command line... [ DONE ]
> Invoking CMake... Not searching for unused variables given on the command line.
-- The CXX compiler identification is Clang 12.0.0 with GNU-like command-line
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/aminy/Documents/GitHub/JavaScript/@atom-ide-community/zadeh/staging/win32/x64/node/93
[ DONE ]
[1/1] Linking C shared library zadeh.node
[ DONE ]
> Copying zadeh.node to target directory... Here
Generic error occured [Error: ENOENT: no such file or directory, stat 'C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\zadeh\staging\win32\x64\node\93\zad
eh.node'] {
errno: -4058,
code: 'ENOENT',
syscall: 'stat',
path: 'C:\\Users\\aminy\\Documents\\GitHub\\JavaScript\\@atom-ide-community\\zadeh\\staging\\win32\\x64\\node\\93\\zadeh.node'
}
I think the error was in my CMake. Now the .node
file is generated with the following cmake file:
cmake_minimum_required(VERSION 3.17)
project(zadeh VERSION "2.0.2" LANGUAGES CXX)
# Source files
file(GLOB_RECURSE SOURCE_FILES "src/binding/*.cc" "src/binding/*.h" "src/*.h")
# .node file target
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
target_compile_features(zadeh PRIVATE cxx_std_17)
# Include paths
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_JS_INC})
# linking libs
target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_JS_LIB})
@martin31821 Any news?
Finally got around to test and fix the bug that prevented me from using it.
Will release as v0.2.0
Thank you for merging. Are you able to add the example you built?
This adds support for NAPI (or any other custom package name).
BREAKING CHANGE renameed customNANPackageName to nodeAPI