Netflix / vmaf

Perceptual video quality assessment based on multi-method fusion.
Other
4.65k stars 755 forks source link

tests: linking with ldd causes issues with missing pthread symbols #1362

Closed 1480c1 closed 7 months ago

1480c1 commented 7 months ago

Using clang64 with msys2 (thus using clang+ldd by default) shows the following error

[127/172] Linking target test/test_feature_extractor.exe
FAILED: test/test_feature_extractor.exe
"cc" @test/test_feature_extractor.exe.rsp
ld.lld: error: undefined symbol: pthread_mutex_init
>>> referenced by src/liblibvmaf_feature.a.p/feature_feature_extractor.c.obj:(vmaf_fex_ctx_pool_create)
>>> referenced by src/liblibvmaf_feature.a.p/feature_feature_collector.c.obj:(vmaf_feature_collector_init)

ld.lld: error: undefined symbol: pthread_mutex_lock
>>> referenced by src/liblibvmaf_feature.a.p/feature_feature_extractor.c.obj:(vmaf_fex_ctx_pool_aquire)
>>> referenced by src/liblibvmaf_feature.a.p/feature_feature_extractor.c.obj:(vmaf_fex_ctx_pool_release)
>>> referenced by src/liblibvmaf_feature.a.p/feature_feature_extractor.c.obj:(vmaf_fex_ctx_pool_flush)
>>> referenced 6 more times

ld.lld: error: undefined symbol: pthread_cond_init
>>> referenced by src/liblibvmaf_feature.a.p/feature_feature_extractor.c.obj:(vmaf_fex_ctx_pool_aquire)

ld.lld: error: undefined symbol: pthread_cond_wait
>>> referenced by src/liblibvmaf_feature.a.p/feature_feature_extractor.c.obj:(vmaf_fex_ctx_pool_aquire)

ld.lld: error: undefined symbol: pthread_mutex_unlock
>>> referenced by src/liblibvmaf_feature.a.p/feature_feature_extractor.c.obj:(vmaf_fex_ctx_pool_aquire)
>>> referenced by src/liblibvmaf_feature.a.p/feature_feature_extractor.c.obj:(vmaf_fex_ctx_pool_release)
>>> referenced by src/liblibvmaf_feature.a.p/feature_feature_extractor.c.obj:(vmaf_fex_ctx_pool_flush)
>>> referenced 5 more times

ld.lld: error: undefined symbol: pthread_cond_signal
>>> referenced by src/liblibvmaf_feature.a.p/feature_feature_extractor.c.obj:(vmaf_fex_ctx_pool_release)

ld.lld: error: undefined symbol: pthread_mutex_destroy
>>> referenced by src/liblibvmaf_feature.a.p/feature_feature_collector.c.obj:(vmaf_feature_collector_destroy)
cc: error: linker command failed with exit code 1 (use -v to see invocation)

I'm pretty sure the fix would be

diff --git a/libvmaf/test/meson.build b/libvmaf/test/meson.build
index 8ae58e51..725fdfea 100644
--- a/libvmaf/test/meson.build
+++ b/libvmaf/test/meson.build
@@ -59,7 +59,7 @@ test_feature_extractor = executable('test_feature_extractor',
     ['test.c', 'test_feature_extractor.c', '../src/mem.c', '../src/picture.c', '../src/ref.c',
      '../src/dict.c', '../src/opt.c', '../src/log.c'],
     include_directories : [libvmaf_inc, test_inc, include_directories('../src/')],
-    dependencies : [math_lib, stdatomic_dependency, cuda_dependency],
+    dependencies : [math_lib, stdatomic_dependency, thread_lib, cuda_dependency],
     objects : [
       common_cuda_objects,
       platform_specific_cpu_objects,

But I'm not sure why it doesn't fail with gcc from the other envs.

My meson command line is meson setup --default-library=static --buildtype=release bui .

There are additionally some warnings that are low-hanging fruit, I've attached the full log. clang64-build.log

1480c1 commented 7 months ago

I have learned why it doesn't fail with gcc

From https://github.com/mesonbuild/meson/pull/13124#issuecomment-2071651121

https://github.com/gcc-mirror/gcc/blob/aa73eb97a1e3c84564fa71158d09f9c5582c4d2e/gcc/config/i386/mingw-pthread.h#L21 https://github.com/gcc-mirror/gcc/blob/aa73eb97a1e3c84564fa71158d09f9c5582c4d2e/gcc/config/i386/mingw32.h#L62

nilfm99 commented 7 months ago

Thanks for raising this, I don't have a handy way to test this but seems OK to add. Do you want to make a PR for this?

1480c1 commented 7 months ago

Sure, give me a few seconds

nilfm99 commented 7 months ago

thank you very much for the contribution @1480c1 !