Skip to content

Commit a2d7439

Browse files
authored
fix!: resolve issue with relative paths during linking (#284)
* fix: resolve issue with relative paths during linking * update docs/InputFormatReference.md * update test.target.mk
1 parent 356f09c commit a2d7439

4 files changed

Lines changed: 8 additions & 4 deletions

File tree

docs/InputFormatReference.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ lists associated with the following keys, are treated as pathnames:
194194
* include\_dirs
195195
* inputs
196196
* libraries
197+
* library\_dirs
197198
* outputs
198199
* sources
199200
* mac\_bundle\_resources
@@ -231,7 +232,8 @@ Source dictionary from `../build/common.gypi`:
231232
```
232233
{
233234
'include_dirs': ['include'], # Treated as relative to ../build
234-
'libraries': ['-lz'], # Not treated as a pathname, begins with a dash
235+
'library_dirs': ['lib'], # Treated as relative to ../build
236+
'libraries': ['-lz'], # Not treated as a pathname, begins with a dash
235237
'defines': ['NDEBUG'], # defines does not contain pathnames
236238
}
237239
```
@@ -250,6 +252,7 @@ Merged dictionary:
250252
{
251253
'sources': ['string_util.cc'],
252254
'include_dirs': ['../build/include'],
255+
'library_dirs': ['../build/lib'],
253256
'libraries': ['-lz'],
254257
'defines': ['NDEBUG'],
255258
}

pylib/gyp/generator/make.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,8 @@ def WriteTarget(
17381738
# into the link command, so we need lots of escaping.
17391739
ldflags.append(r"-Wl,-rpath=\$$ORIGIN/")
17401740
ldflags.append(r"-Wl,-rpath-link=\$(builddir)/")
1741-
library_dirs = config.get("library_dirs", [])
1741+
if library_dirs := config.get("library_dirs", []):
1742+
library_dirs = [Sourceify(self.Absolutify(i)) for i in library_dirs]
17421743
ldflags += [("-L%s" % library_dir) for library_dir in library_dirs]
17431744
self.WriteList(ldflags, "LDFLAGS_%s" % configname)
17441745
if self.flavor == "mac":

test/fixtures/expected-darwin/make/test.target.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ LDFLAGS_Default := \
6161
-arch \
6262
x86_64 \
6363
-L$(builddir) \
64-
-Lmylib
64+
-L$(srcdir)/mylib
6565

6666
LIBTOOLFLAGS_Default :=
6767

test/fixtures/expected-linux/make/test.target.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ $(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.cc FORCE_DO_CMD
4444
# End of this set of suffix rules
4545
### Rules for final target.
4646
LDFLAGS_Default := \
47-
-Lmylib
47+
-L$(srcdir)/mylib
4848

4949
LIBS :=
5050

0 commit comments

Comments
 (0)