|
1 | 1 | const opencvBuild = require(`@nut-tree/opencv-build-${process.platform}`)
|
2 | 2 | const child_process = require('child_process')
|
| 3 | +const { basename } = require("path"); |
3 | 4 | const fs = require('fs')
|
4 | 5 | const log = require('npmlog')
|
5 | 6 | const { resolvePath } = require('../lib/commons')
|
@@ -58,11 +59,23 @@ const defines = libsFoundInDir
|
58 | 59 | // : [resolvePath(opencvBuild.opencvInclude), resolvePath(opencvBuild.opencv4Include)]
|
59 | 60 | const includes = [resolvePath(opencvBuild.opencvInclude), resolvePath(opencvBuild.opencv4Include)]
|
60 | 61 |
|
| 62 | +// linkLib produces linker flags for GNU ld and BSD ld |
| 63 | +// It generates linker flags based on the libPath, which make dealing with version numbers in lib names easier |
| 64 | +// On Linux, it passes the full path via -l:/path/to/lib which links against the given file |
| 65 | +// On macOS it strips the *.dylib suffix and the lib prefix and passes the result to via -l |
| 66 | +// This results in e.g. -lopencv_world.4.1 |
| 67 | +const linkLib = (lib) => { |
| 68 | + if (opencvBuild.isOSX()) { |
| 69 | + return `-l${basename(lib.libPath, ".dylib").replace("lib", "")}`; |
| 70 | + } else { |
| 71 | + return `-l:${basename(lib.libPath)}`; |
| 72 | + } |
| 73 | +} |
61 | 74 | const libs = opencvBuild.isWin()
|
62 | 75 | ? libsFoundInDir.map(lib => resolvePath(lib.libPath))
|
63 | 76 | // dynamically link libs if not on windows
|
64 | 77 | : ['-L' + libDir]
|
65 |
| - .concat(libsFoundInDir.map(lib => '-lopencv_' + lib.opencvModule)) |
| 78 | + .concat(libsFoundInDir.map(lib => linkLib(lib))) |
66 | 79 | .concat('-Wl,-rpath,' + libDir)
|
67 | 80 |
|
68 | 81 | console.log()
|
|
0 commit comments