Skip to content

Commit a9b347b

Browse files
authored
Add a test case for shared library dependencies. NFC (#21682)
This change doesn't fix #21667 but just encodes the current behavior in a test. As a followup we could consider resolving shared libraries dependencies based on previous command line arguments which would solve #21667 without the need for adding `-L.`.
1 parent 597ffc1 commit a9b347b

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

test/test_other.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,6 +2221,46 @@ def test_dylink_no_autoload(self):
22212221
output = self.run_js('a.out.js')
22222222
self.assertContained('sidey: 42\n', output)
22232223

2224+
def test_dylink_dependencies(self):
2225+
create_file('side1.c', r'''
2226+
#include <stdio.h>
2227+
#include <stdlib.h>
2228+
2229+
void side2();
2230+
2231+
void side1() {
2232+
printf("side1\n");
2233+
side2();
2234+
}
2235+
''')
2236+
create_file('side2.c', r'''
2237+
#include <stdio.h>
2238+
#include <stdlib.h>
2239+
2240+
void side2() {
2241+
printf("side2\n");
2242+
}
2243+
''')
2244+
create_file('main.c', '''
2245+
void side1();
2246+
2247+
int main() {
2248+
side1();
2249+
return 0;
2250+
}
2251+
''')
2252+
self.emcc('side2.c', ['-fPIC', '-sSIDE_MODULE', '-olibside2.so'])
2253+
self.emcc('side1.c', ['-fPIC', '-sSIDE_MODULE', '-olibside1.so', 'libside2.so'])
2254+
cmd = [EMCC, 'main.c', '-fPIC', '-sMAIN_MODULE=2', 'libside1.so']
2255+
2256+
# Unless `.` is added to the library path the libside2.so won't be found.
2257+
err = self.expect_fail(cmd)
2258+
self.assertContained('emcc: error: libside1.so: shared library dependency not found in library path: `libside2.so`.', err)
2259+
2260+
# Adding -L. to the library path makes it work.
2261+
self.run_process(cmd + ['-L.'])
2262+
self.run_js('a.out.js')
2263+
22242264
def test_js_link(self):
22252265
create_file('main.c', '''
22262266
#include <stdio.h>
@@ -8664,7 +8704,7 @@ def test_side_module_missing(self):
86648704
# When linking against `libside2.wasm` (which depends on libside1.wasm) that library path is used
86658705
# to locate `libside1.wasm`. Expect the link to fail with an unmodified library path.
86668706
err = self.expect_fail([EMCC, '-sMAIN_MODULE=2', test_file('hello_world.c'), 'libside2.wasm'])
8667-
self.assertContained('libside2.wasm: shared library dependency not found: `libside1.wasm`', err)
8707+
self.assertContained('libside2.wasm: shared library dependency not found in library path: `libside1.wasm`', err)
86688708

86698709
# But succeed if `.` is added the library path.
86708710
self.run_process([EMCC, '-sMAIN_MODULE=2', test_file('hello_world.c'), '-L.', 'libside2.wasm'])
@@ -8680,7 +8720,7 @@ def test_side_module_transitive_deps(self):
86808720
self.run_process(final_link)
86818721
os.remove('libside1.wasm')
86828722
err = self.expect_fail(final_link)
8683-
self.assertContained('error: libside2.wasm: shared library dependency not found: `libside1.wasm`', err)
8723+
self.assertContained('error: libside2.wasm: shared library dependency not found in library path: `libside1.wasm`', err)
86848724

86858725
def test_side_module_folder_deps(self):
86868726
# Build side modules in a subfolder

tools/link.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2754,7 +2754,7 @@ def process_dynamic_libs(dylibs, lib_dirs):
27542754
extras.append(path)
27552755
seen.add(needed)
27562756
else:
2757-
exit_with_error(f'{os.path.normpath(dylib)}: shared library dependency not found: `{needed}`')
2757+
exit_with_error(f'{os.path.normpath(dylib)}: shared library dependency not found in library path: `{needed}`. (library path: {lib_dirs}')
27582758
to_process.append(path)
27592759

27602760
dylibs += extras

0 commit comments

Comments
 (0)