Skip to content

Commit ad083ee

Browse files
Hussein NasserHussein Nasser
authored andcommitted
cpp
1 parent b7d4341 commit ad083ee

File tree

11 files changed

+112
-37
lines changed

11 files changed

+112
-37
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cmd_Debug/nothing.a := rm -f Debug/nothing.a && ./gyp-mac-tool filter-libtool libtool -static -o Debug/nothing.a Debug/obj.target/nothing/node_modules/node-addon-api/nothing.o
1+
cmd_Debug/nothing.a := rm -f Debug/nothing.a && /opt/homebrew/opt/[email protected]/bin/python3.13 gyp-mac-tool filter-libtool libtool -static -o Debug/nothing.a Debug/obj.target/nothing/node_modules/node-addon-api/nothing.o
Binary file not shown.

27-nodecpp-addon/build/Debug/sum.node

0 Bytes
Binary file not shown.

27-nodecpp-addon/build/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ cmd_pch_mm = $(CC.$(TOOLSET)) $(GYP_PCH_OBJCXXFLAGS) $(DEPFLAGS) -c -o $@ $<
148148
# Use $(4) for the command, since $(2) and $(3) are used as flag by do_cmd
149149
# already.
150150
quiet_cmd_mac_tool = MACTOOL $(4) $<
151-
cmd_mac_tool = ./gyp-mac-tool $(4) $< "$@"
151+
cmd_mac_tool = /opt/homebrew/opt/[email protected]/bin/python3.13 gyp-mac-tool $(4) $< "$@"
152152

153153
quiet_cmd_mac_package_framework = PACKAGE FRAMEWORK $@
154-
cmd_mac_package_framework = ./gyp-mac-tool package-framework "$@" $(4)
154+
cmd_mac_package_framework = /opt/homebrew/opt/[email protected]/bin/python3.13 gyp-mac-tool package-framework "$@" $(4)
155155

156156
quiet_cmd_infoplist = INFOPLIST $@
157157
cmd_infoplist = $(CC.$(TOOLSET)) -E -P -Wno-trigraphs -x c $(INFOPLIST_DEFINES) "$<" -o "$@"
@@ -167,7 +167,7 @@ quiet_cmd_symlink = SYMLINK $@
167167
cmd_symlink = ln -sf "$<" "$@"
168168

169169
quiet_cmd_alink = LIBTOOL-STATIC $@
170-
cmd_alink = rm -f $@ && ./gyp-mac-tool filter-libtool libtool $(GYP_LIBTOOLFLAGS) -static -o $@ $(filter %.o,$^)
170+
cmd_alink = rm -f $@ && /opt/homebrew/opt/[email protected]/bin/python3.13 gyp-mac-tool filter-libtool libtool $(GYP_LIBTOOLFLAGS) -static -o $@ $(filter %.o,$^)
171171

172172
quiet_cmd_link = LINK($(TOOLSET)) $@
173173
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS)
@@ -336,8 +336,8 @@ ifeq ($(strip $(foreach prefix,$(NO_LOAD),\
336336
endif
337337

338338
quiet_cmd_regen_makefile = ACTION Regenerating $@
339-
cmd_regen_makefile = cd $(srcdir); /Users/HusseinNasser/projects/node-course-content/28-nodecpp-addon/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/Users/HusseinNasser/Library/Caches/node-gyp/23.5.0" "-Dnode_gyp_dir=/Users/HusseinNasser/projects/node-course-content/28-nodecpp-addon/node_modules/node-gyp" "-Dnode_lib_file=/Users/HusseinNasser/Library/Caches/node-gyp/23.5.0/<(target_arch)/node.lib" "-Dmodule_root_dir=/Users/HusseinNasser/projects/node-course-content/28-nodecpp-addon" "-Dnode_engine=v8" "--depth=." "-Goutput_dir=." "--generator-output=build" -I/Users/HusseinNasser/projects/node-course-content/28-nodecpp-addon/build/config.gypi -I/Users/HusseinNasser/projects/node-course-content/28-nodecpp-addon/node_modules/node-gyp/addon.gypi -I/Users/HusseinNasser/Library/Caches/node-gyp/23.5.0/include/node/common.gypi "--toplevel-dir=." binding.gyp
340-
Makefile: $(srcdir)/node_modules/node-gyp/addon.gypi $(srcdir)/build/config.gypi $(srcdir)/binding.gyp $(srcdir)/../../../Library/Caches/node-gyp/23.5.0/include/node/common.gypi $(srcdir)/node_modules/node-addon-api/node_api.gyp
339+
cmd_regen_makefile = cd $(srcdir); /Users/HusseinNasser/projects/node-course-content/27-nodecpp-addon/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/Users/HusseinNasser/Library/Caches/node-gyp/23.5.0" "-Dnode_gyp_dir=/Users/HusseinNasser/projects/node-course-content/27-nodecpp-addon/node_modules/node-gyp" "-Dnode_lib_file=/Users/HusseinNasser/Library/Caches/node-gyp/23.5.0/<(target_arch)/node.lib" "-Dmodule_root_dir=/Users/HusseinNasser/projects/node-course-content/27-nodecpp-addon" "-Dnode_engine=v8" "--depth=." "-Goutput_dir=." "--generator-output=build" -I/Users/HusseinNasser/projects/node-course-content/27-nodecpp-addon/build/config.gypi -I/Users/HusseinNasser/projects/node-course-content/27-nodecpp-addon/node_modules/node-gyp/addon.gypi -I/Users/HusseinNasser/Library/Caches/node-gyp/23.5.0/include/node/common.gypi "--toplevel-dir=." binding.gyp
340+
Makefile: $(srcdir)/node_modules/node-gyp/addon.gypi $(srcdir)/build/config.gypi $(srcdir)/../../../Library/Caches/node-gyp/23.5.0/include/node/common.gypi $(srcdir)/binding.gyp $(srcdir)/node_modules/node-addon-api/node_api.gyp
341341
$(call do_cmd,regen_makefile)
342342

343343
# "all" is a concatenation of the "all" targets from all the included

27-nodecpp-addon/build/config.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@
449449
"python": "/opt/homebrew/opt/[email protected]/bin/python3.13",
450450
"standalone_static_library": 1,
451451
"global_prefix": "/usr/local",
452-
"local_prefix": "/Users/HusseinNasser/projects/node-course-content/28-nodecpp-addon",
452+
"local_prefix": "/Users/HusseinNasser/projects/node-course-content/27-nodecpp-addon",
453453
"globalconfig": "/usr/local/etc/npmrc",
454454
"userconfig": "/Users/HusseinNasser/.npmrc",
455455
"init_module": "/Users/HusseinNasser/.npm-init.js",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Mac",
5+
"includePath": [
6+
"/Users/HusseinNasser/projects/node-course-content/27-nodecpp-addon/node_modules/**",
7+
"/Users/HusseinNasser/projects/node-course-content/27-nodecpp-addon/node_modules/node-addon-api",
8+
"/Users/HusseinNasser/projects/node-course-content/27-nodecpp-addon/node_modules/node-addon-api/include",
9+
"/Users/HusseinNasser/projects/node-course-content/27-nodecpp-addon/node_modules/node_modules/node-addon-api/napi.h",
10+
"/usr/local/include/node", // Node.js headers (macOS/Linux)
11+
"/usr/include/node", // Alternative Node.js include path
12+
"C:/Program Files/nodejs/include/node" // Windows (if applicable)
13+
],
14+
"defines": [],
15+
"compilerPath": "/usr/bin/clang++",
16+
"cStandard": "c11",
17+
"cppStandard": "c++17",
18+
"intelliSenseMode": "macos-clang-x64"
19+
}
20+
],
21+
"version": 4
22+
}

27-nodecpp-addon/launch.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
{
3+
// Use IntelliSense to learn about possible attributes.
4+
// Hover to view descriptions of existing attributes.
5+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
6+
"version": "0.2.0",
7+
"configurations": [
8+
{
9+
"name": "Debug Node.js Addon",
10+
"type": "cppdbg",
11+
"request": "launch",
12+
"program": "/usr/local/bin/node",
13+
"args": ["/Users/HusseinNasser/projects/node-course-content/27-nodecpp-addon/index.js"],
14+
"stopAtEntry": false,
15+
"cwd": "${workspaceFolder}",
16+
"externalConsole": false,
17+
"MIMode": "lldb", // Use "gdb" for Linux
18+
"setupCommands": [
19+
{ "text": "-enable-pretty-printing", "description": "Enable pretty printing", "ignoreFailures": true }
20+
]
21+
}
22+
]
23+
}

27-nodecpp-addon/package-lock.json

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

27-nodecpp-addon/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "28-isprime.cpp",
2+
"name": "27-nodecpp-addon",
33
"version": "1.0.0",
44
"main": "index.js",
55
"scripts": {
@@ -12,7 +12,7 @@
1212
"gypfile": true,
1313
"description": "",
1414
"dependencies": {
15-
"node-addon-api": "^8.3.0",
16-
"node-gyp": "^11.0.0"
15+
"node-addon-api": "^8.3.1",
16+
"node-gyp": "^11.1.0"
1717
}
1818
}

27-nodecpp-addon/readme.txt

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ npm install will run the build
3737

3838
npm install
3939

40+
41+
//to remove the .cpp errors, copy the c_cpp_properties.json to .vscode
42+
//this tells vscode where to find NAPI
43+
44+
4045
//to Debug
4146

4247
change package.json install and add Debug
43-
48+
//change your paths
4449
, add launcher .json
4550

4651
{
@@ -54,7 +59,7 @@ change package.json install and add Debug
5459
"type": "cppdbg",
5560
"request": "launch",
5661
"program": "/usr/local/bin/node",
57-
"args": ["/Users/HusseinNasser/projects/node-course-content/28-nodecpp-addon/index.js"],
62+
"args": ["/Users/HusseinNasser/projects/node-course-content/27-nodecpp-addon/index.js"],
5863
"stopAtEntry": false,
5964
"cwd": "${workspaceFolder}",
6065
"externalConsole": false,
@@ -64,4 +69,28 @@ change package.json install and add Debug
6469
]
6570
}
6671
]
67-
}
72+
}
73+
74+
75+
76+
package.json should have node-gyp rebuild --debug or --release which builds
77+
78+
{
79+
"name": "28-isprime.cpp",
80+
"version": "1.0.0",
81+
"main": "index.js",
82+
"scripts": {
83+
"test": "echo \"Error: no test specified\" && exit 1",
84+
"install": "node-gyp rebuild --debug"
85+
},
86+
"keywords": [],
87+
"author": "",
88+
"license": "ISC",
89+
"gypfile": true,
90+
"description": "",
91+
"dependencies": {
92+
"node-addon-api": "^8.3.0",
93+
"node-gyp": "^11.0.0"
94+
}
95+
}
96+

27-nodecpp-addon/sum.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <napi.h>
1+
#include "node_modules/node-addon-api/napi.h"
22

33
// Function that adds two numbers and returns the result via a callback
44
void AddNumbers(const Napi::CallbackInfo& info) {
@@ -9,6 +9,7 @@ void AddNumbers(const Napi::CallbackInfo& info) {
99
Napi::Object console = global.Get("console").As<Napi::Object>();
1010

1111
// Get `log` function from `console`
12+
//console.log
1213
Napi::Function log = console.Get("log").As<Napi::Function>();
1314

1415
// Call `console.log("Hello from C++ addon!")`

0 commit comments

Comments
 (0)