1

I am trying to make node.js native addon which use cmake to compile c++ code...

CMakeLists.txt file

cmake_minimum_required(VERSION 3.15)
# Name of the project (will be the name of the plugin)
project (addon)
set(CMAKE_CXX_STANDARD 11)
# Don't add this line if you will try_compile with boost.
# set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(Boost_USE_STATIC_LIBS ON) 
set(Boost_USE_MULTITHREADED OFF)  
set(Boost_USE_STATIC_RUNTIME ON)
find_package(Boost)

# Essential include files to build a node addon,
# you should add this line in every CMake.js based project.
include_directories(${CMAKE_JS_INC} ${Boost_INCLUDE_DIRS})
# Declare the location of the source files
file(GLOB SOURCE_FILES "src/*.cpp" "src/*.h")
# This line will tell CMake that we're building a shared library
# from the above source files
# named after the project's name
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
# This line will give our library file a .node extension without any "lib" prefix
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
# Essential library files to link to a node addon,
# you should add this line in every CMake.js based project.
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB} ${Boost_LIBRARIES})
# Include N-API wrappers
execute_process(COMMAND node -p "require('node-addon-api').include"
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        OUTPUT_VARIABLE NODE_ADDON_API_DIR
        )
string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${NODE_ADDON_API_DIR})
add_definitions(-DNAPI_VERSION=3)

I am using websocketpp library which is internally dependent on boost

And while compiling I am getting this error:

LINK : fatal error LNK1104: cannot open file 'libboost_random-vc142-mt-x64-1_74.lib' [C:\Users\atiqg\Desktop\Tom\muteme\shells\electron\na 
tive_module\build\addon.vcxproj]

libboost_random-vc142-mt-x64-1_74.lib is present in boost_1_71_0/stage/x64/lib folder
And this path is added in environments variables too....

AtiqGauri
  • 1,483
  • 13
  • 26
  • 2
    You built the boost 1.74 libs in the directory for the boost 1.71 build? Also you did not use `install` when building boost? It pretty much looks like you're trying to use the non-installed build results directly and those may contain paths to the location where b2 was expected to install the files; it could also be the case that the relative position of the files is incorrect, unless you install the files. – fabian Nov 22 '20 at 08:19
  • @fabian Thanks for reply... Boost_1_71_0 folder is made by me custom in that I have added 1.74.0 unzipped content and then executed bootsrap and then ./b2........ – AtiqGauri Nov 22 '20 at 11:32
  • @fabian can you please tell me correct build and install command for windows X64... So I can build this again... – AtiqGauri Nov 23 '20 at 02:15
  • @fabian I am using this command to build `.\b2 -j8 toolset=msvc address-model=64 architecture=x64 link=static threading=multi runtime-link=shared --build-type=complete stage` and then adding stage/lib folder to path variable... So yeah there is not any install command but can you help me with that? – AtiqGauri Nov 23 '20 at 02:57
  • Seems mostly correct, but I did not use `-j8` (probably does not make a difference); Also I'm pretty sure `architecture` should bt `x86`, not `x64`. Moreover in my case there in place of `stage` I used `install` in addition to adding the `--prefix=` option (quoted, if necessary): `.\b2 -j8 toolset=msvc address-model=64 architecture=x86 link=static threading=multi runtime-link=shared --build-type=complete "--prefix=C:/Some Dir/boost" install` – fabian Nov 23 '20 at 21:18

0 Answers0