diff mbox series

[FFmpeg-devel] libavformat\file:Fix duplicate JNI symbols

Message ID 20240323190518.1031-1-admin@shaoxia.xyz
State New
Headers show
Series [FFmpeg-devel] libavformat\file:Fix duplicate JNI symbols | expand

Checks

Context Check Description
yinshiyou/commit_msg_loongarch64 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/commit_msg_x86 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

admin@shaoxia.xyz March 23, 2024, 7:05 p.m. UTC
From: 联盟少侠 <admin@shaoxia.xyz>

The errors indicate that there are multiple definitions of several JNI (Java Native Interface) symbols in the FFmpeg library. Specifically, the linker ld.lld has found duplicate definitions for the following symbols:

- ff_jni_get_env
- ff_jni_jstring_to_utf_chars
- ff_jni_utf_chars_to_jstring
- ff_jni_exception_get_summary
- ff_jni_exception_check
- ff_jni_init_jfields
- ff_jni_reset_jfields

These symbols are defined in both libavcodec.a and libavformat.a archives, leading to conflicts during the linking process. The duplicates are found in the same source file ffjni.c, but they are being compiled into two different static libraries.

To resolve these errors, ensure that each symbol is defined only once across all linked libraries, or if these symbols are required in both libraries, they should be marked as weak symbols to allow the linker to handle them appropriately. Additionally, check for any build script misconfigurations that may be causing the same file to be included in multiple libraries.
---
 libavformat/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Zhao Zhili March 24, 2024, 2:16 a.m. UTC | #1
On 2024/3/24 03:05, admin@shaoxia.xyz wrote:
> From: 联盟少侠 <admin@shaoxia.xyz>
Could you configure git to avoid Chinese character?
>
> The errors indicate that there are multiple definitions of several JNI (Java Native Interface) symbols in the FFmpeg library. Specifically, the linker ld.lld has found duplicate definitions for the following symbols:
How to reproduce the error?
>
> - ff_jni_get_env
> - ff_jni_jstring_to_utf_chars
> - ff_jni_utf_chars_to_jstring
> - ff_jni_exception_get_summary
> - ff_jni_exception_check
> - ff_jni_init_jfields
> - ff_jni_reset_jfields
>
> These symbols are defined in both libavcodec.a and libavformat.a archives, leading to conflicts during the linking process. The duplicates are found in the same source file ffjni.c, but they are being compiled into two different static libraries.
>
> To resolve these errors, ensure that each symbol is defined only once across all linked libraries, or if these symbols are required in both libraries, they should be marked as weak symbols to allow the linker to handle them appropriately. Additionally, check for any build script misconfigurations that may be causing the same file to be included in multiple libraries.
> ---
>   libavformat/file.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavformat/file.c b/libavformat/file.c
> index dd5819c..fa13ae9 100644
> --- a/libavformat/file.c
> +++ b/libavformat/file.c
> @@ -43,7 +43,7 @@
>   #if CONFIG_ANDROID_CONTENT_PROTOCOL
>   #include <jni.h>
>   #include "libavcodec/jni.h"
> -#include "libavcodec/ffjni.c"
> +#include "libavcodec/ffjni.h"
>   #endif
This just break --enable-shared, so NACK.
>   
>
Zhao Zhili March 24, 2024, 4:09 a.m. UTC | #2
On 2024/3/24 10:16, Zhao Zhili wrote:
>
>> diff --git a/libavformat/file.c b/libavformat/file.c
>> index dd5819c..fa13ae9 100644
>> --- a/libavformat/file.c
>> +++ b/libavformat/file.c
>> @@ -43,7 +43,7 @@
>>   #if CONFIG_ANDROID_CONTENT_PROTOCOL
>>   #include <jni.h>
>>   #include "libavcodec/jni.h"
>> -#include "libavcodec/ffjni.c"
>> +#include "libavcodec/ffjni.h"
>>   #endif
> This just break --enable-shared, so NACK.

The following patch should work for static and shared both.

https://ffmpeg.org/pipermail/ffmpeg-devel/2024-March/324138.html
Andreas Rheinhardt March 24, 2024, 1:23 p.m. UTC | #3
admin@shaoxia.xyz:
> From: 联盟少侠 <admin@shaoxia.xyz>
> 
> The errors indicate that there are multiple definitions of several JNI (Java Native Interface) symbols in the FFmpeg library. Specifically, the linker ld.lld has found duplicate definitions for the following symbols:
> 
> - ff_jni_get_env
> - ff_jni_jstring_to_utf_chars
> - ff_jni_utf_chars_to_jstring
> - ff_jni_exception_get_summary
> - ff_jni_exception_check
> - ff_jni_init_jfields
> - ff_jni_reset_jfields
> 
> These symbols are defined in both libavcodec.a and libavformat.a archives, leading to conflicts during the linking process. The duplicates are found in the same source file ffjni.c, but they are being compiled into two different static libraries.
> 
> To resolve these errors, ensure that each symbol is defined only once across all linked libraries, or if these symbols are required in both libraries, they should be marked as weak symbols to allow the linker to handle them appropriately. Additionally, check for any build script misconfigurations that may be causing the same file to be included in multiple libraries.
> ---
>  libavformat/file.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/file.c b/libavformat/file.c
> index dd5819c..fa13ae9 100644
> --- a/libavformat/file.c
> +++ b/libavformat/file.c
> @@ -43,7 +43,7 @@
>  #if CONFIG_ANDROID_CONTENT_PROTOCOL
>  #include <jni.h>
>  #include "libavcodec/jni.h"
> -#include "libavcodec/ffjni.c"
> +#include "libavcodec/ffjni.h"
>  #endif
>  
>  

How can this even happen? In case of static builds with the android
content protocol enabled, libavformat/file.o provides all the symbols
that libavcodec/ffjni.o also provides. Given that the former is part of
libavformat.a and this is linked before libavcodec.a, the stuff from the
former is used and the ffjni.o in libavcodec.a should not be pulled in
at all.

- Andreas
Zhao Zhili March 24, 2024, 2:59 p.m. UTC | #4
On 2024/3/24 21:23, Andreas Rheinhardt wrote:
> admin@shaoxia.xyz:
>> From: 联盟少侠 <admin@shaoxia.xyz>
>>
>> The errors indicate that there are multiple definitions of several JNI (Java Native Interface) symbols in the FFmpeg library. Specifically, the linker ld.lld has found duplicate definitions for the following symbols:
>>
>> - ff_jni_get_env
>> - ff_jni_jstring_to_utf_chars
>> - ff_jni_utf_chars_to_jstring
>> - ff_jni_exception_get_summary
>> - ff_jni_exception_check
>> - ff_jni_init_jfields
>> - ff_jni_reset_jfields
>>
>> These symbols are defined in both libavcodec.a and libavformat.a archives, leading to conflicts during the linking process. The duplicates are found in the same source file ffjni.c, but they are being compiled into two different static libraries.
>>
>> To resolve these errors, ensure that each symbol is defined only once across all linked libraries, or if these symbols are required in both libraries, they should be marked as weak symbols to allow the linker to handle them appropriately. Additionally, check for any build script misconfigurations that may be causing the same file to be included in multiple libraries.
>> ---
>>   libavformat/file.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavformat/file.c b/libavformat/file.c
>> index dd5819c..fa13ae9 100644
>> --- a/libavformat/file.c
>> +++ b/libavformat/file.c
>> @@ -43,7 +43,7 @@
>>   #if CONFIG_ANDROID_CONTENT_PROTOCOL
>>   #include <jni.h>
>>   #include "libavcodec/jni.h"
>> -#include "libavcodec/ffjni.c"
>> +#include "libavcodec/ffjni.h"
>>   #endif
>>   
>>   
> How can this even happen? In case of static builds with the android
> content protocol enabled, libavformat/file.o provides all the symbols
> that libavcodec/ffjni.o also provides. Given that the former is part of
> libavformat.a and this is linked before libavcodec.a, the stuff from the
> former is used and the ffjni.o in libavcodec.a should not be pulled in
> at all.
I guess the error is triggered by creating a shared library from combine 
all static libraries
via -Wl,--whole-archive. It's a common practice to reduce the number of 
shared libraries
in mobile app.
>
> - Andreas
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavformat/file.c b/libavformat/file.c
index dd5819c..fa13ae9 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -43,7 +43,7 @@ 
 #if CONFIG_ANDROID_CONTENT_PROTOCOL
 #include <jni.h>
 #include "libavcodec/jni.h"
-#include "libavcodec/ffjni.c"
+#include "libavcodec/ffjni.h"
 #endif