Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 9801aff

Browse files
committed
(#4) Updated defaults to link correct libs
1 parent 2f5cfe4 commit 9801aff

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

install/defaults.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const opencvBuild = require(`@nut-tree/opencv-build-${process.platform}`)
22
const { resolvePath } = require('../lib/commons')
33
const fs = require('fs')
4+
const { basename } = require("path");
45

56
const libDir = resolvePath(opencvBuild.opencvLibDir);
67

@@ -23,12 +24,24 @@ const inc = [
2324
resolvePath(opencvBuild.opencv4Include)
2425
];
2526

27+
// linkLib produces linker flags for GNU ld and BSD ld
28+
// It generates linker flags based on the libPath, which make dealing with version numbers in lib names easier
29+
// On Linux, it passes the full path via -l:/path/to/lib which links against the given file
30+
// On macOS it strips the *.dylib suffix and the lib prefix and passes the result to via -l
31+
// This results in e.g. -lopencv_world.4.1
32+
const linkLib = (lib) => {
33+
if (opencvBuild.isOSX()) {
34+
return `-l${basename(lib.libPath, ".dylib").replace("lib", "")}`;
35+
} else {
36+
return `-l:${basename(lib.libPath)}`;
37+
}
38+
}
2639
const libs = opencvBuild.isWin()
2740
? libsFoundInDir.map(lib => resolvePath(lib.libPath))
28-
: // dynamically link libs if not on windows
29-
["-L" + libDir]
30-
.concat(libsFoundInDir.map(lib => "-lopencv_" + lib.opencvModule))
31-
.concat("-Wl,-rpath," + libDir);
41+
// dynamically link libs if not on windows
42+
: ['-L' + libDir]
43+
.concat(libsFoundInDir.map(lib => linkLib(lib)))
44+
.concat('-Wl,-rpath,' + libDir)
3245

3346
module.exports = {
3447
OPENCV4NODEJS_LIBRARIES: () => libs.join("\n"),

0 commit comments

Comments
 (0)