我正在尝试为VLC创建一个解码器模块,为了创建最终的共享库,我需要访问libvlc.dylib和libvlccore.dylib中定义的函数。但是,当我尝试将目标文件与 VLC 库链接时,我收到此错误:
Undefined symbols for architecture arm64:
"_block_Release", referenced from:
_Decode in my_decoder.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是我正在运行的链接命令:
g++ my_decoder.o -L/Applications/VLC.app/Contents/MacOS/lib -lvlc -lvlccore -dynamiclib -o libmy_decoder.dylib
这是 my_decoder.c 的内容:
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_codec.h>
#define MODULE_STRING "My Decoder"
vlc_module_begin()
/*
* Module details
* Set capability and function callbacks
*/
vlc_module_end()
static int Open(vlc_object_t *p_this) {
/*
* Create the decoder
* Set pf_decode = Decode;
*/
return VLCDEC_SUCCESS;
}
static int Decode(decoder_t *p_dec, block_t *p_block) {
/*
* Decode the data in p_block, and create p_pic
*/
// decoder_QueueVideo does not produce linking errors
decoder_QueueVideo(p_dec, &p_pic);
// block_Release cannot be identified by linker
block_Release(p_block);
return VLCDEC_SUCCESS;
}
static int Close(vlc_object_t *p_this) {
/*
* Close the decoder
*/
return VLC_SUCCESS;
}
我使用以下命令编译 my_decoder.c:
gcc -std=gnu99 -I/path/to/vlc/header/files/ -g -Wall -fPIC my_decoder.c -c -o my_decoder.o
备注:
如果您的两个
dylib
是通用的,则需要剥离 x86_64 部分:
lipo -remove x86_64 /path/to/fatlib.dylib -output /path/to/thinlib.dylib
lipo -info
会告诉你它是否胖,以及存在哪些架构:% lipo /path/to/fatlib.dylib
Architectures in the fat file: /path/to/fatlib.dylib are: x86_64 arm64
file
检查存在哪些架构:% file /path/to/fatlib.dylib
/path/to/fatlib.dylib: Mach-O universal binary with 2 architectures:
[x86_64:Mach-O 64-bit dynamically linked shared library x86_64
- Mach-O 64-bit dynamically linked shared library x86_64] [arm64]
/path/to/fatlib.dylib (for architecture x86_64): Mach-O 64-bit
dynamically linked shared library x86_64
/path/to/fatlib.dylib (for architecture arm64): Mach-O 64-bit
dynamically linked shared library arm64