英文:
Can Emscripten link libraries (static ".a" archive files) built for MacOS?
问题
I am trying to link some libraries for my WebAssembly project.
我正在尝试为我的WebAssembly项目链接一些库。
I am using a CMakeLists.txt file rather than directly in the command line.
我正在使用CMakeLists.txt文件而不是直接在命令行中。
I have read that it is possible to link static libraries in Emscripten, using archive files (.a) which I conveniently already have built and tested or the MacOS version of the project.
我已经阅读到可以在Emscripten中链接静态库,使用归档文件(.a),这些文件我已经方便地构建和测试,或者是项目的MacOS版本。
Can I use the same .a files for Emscripten?
我可以在Emscripten中使用相同的.a文件吗?
I have added the include directory in CMakeLists.txt like so:
我已经在CMakeLists.txt中添加了include目录,如下所示:
And I have added the link directory like so:
我已经添加了link目录,如下所示:
The next line is for the executable, which I understand goes before the library files (below):
下一行是用于可执行文件的,我理解它位于库文件之前(下面)。
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
最后,我像这样添加了库文件:
link_libraries(
"${PROJECT_SOURCE_DIR}/../External/macports/ffmpeg_5.1.2_6/lib/libavcodec.a"
"${PROJECT_SOURCE_DIR}/../External/macports/ffmpeg_5.1.2_6/lib/libavdevice.a"
"${PROJECT_SOURCE_DIR}/../External/macports/ffmpeg_5.1.2_6/lib/libavfilter.a"
"${PROJECT_SOURCE_DIR}/../External/macports/ffmpeg_5.1.2_6/lib/libavformat.a"
"${PROJECT_SOURCE_DIR}/../External/macports/ffmpeg_5.1.2_6/lib/libavutil.a"
"${PROJECT_SOURCE_DIR}/../External/macports/ffmpeg_5.1.2_6/lib/libswresample.a"
"${PROJECT_SOURCE_DIR}/../External/macports/ffmpeg_5.1.2_6/lib/libswscale.a"
)
程序构建(达到100%),但在链接阶段出现以下错误:
Linking CXX executable Build\project_wasm.html
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_frame_unref
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_packet_unref
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: avcodec_close
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: avcodec_close
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_frame_unref
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_packet_unref
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: avcodec_close
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: avcodec_close
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_malloc
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_packet_alloc
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_frame_alloc
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: avcodec_receive_frame
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: avcodec_send_packet
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_mallocz
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: swr_alloc
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_get_channel_layout_nb_channels
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_get_default_channel_layout
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_opt_set_int
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_opt_set_int
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_opt_set_sample_fmt
英文:
I am trying to link some libraries for my WebAssembly project.
I am using a CMakeLists.txt file rather than directly in the command line.
I have read that it is possible to link static libraries in Emscripten, using archive files (.a) which I conveniently already have built and tested or the MacOS version of the project.
Can I use the same .a files for Emscripten?
I have added the include directory in CMakeLists.txt like so:
include_directories(
...
"${CMAKE_SOURCE_DIR}/../External/macports/ffmpeg_5.1.2_6/include/"
)
And I have added the link directory like so:
link_directories(
...
"${PROJECT_SOURCE_DIR}/../External/macports/ffmpeg_5.1.2_6/lib/"
)
The next line is for the executable, which I understand goes before the library files (below):
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
And finally I am adding the library files like so:
link_libraries(
"${PROJECT_SOURCE_DIR}/../External/macports/ffmpeg_5.1.2_6/lib/libavcodec.a"
"${PROJECT_SOURCE_DIR}/../External/macports/ffmpeg_5.1.2_6/lib/libavdevice.a"
"${PROJECT_SOURCE_DIR}/../External/macports/ffmpeg_5.1.2_6/lib/libavfilter.a"
"${PROJECT_SOURCE_DIR}/../External/macports/ffmpeg_5.1.2_6/lib/libavformat.a"
"${PROJECT_SOURCE_DIR}/../External/macports/ffmpeg_5.1.2_6/lib/libavutil.a"
"${PROJECT_SOURCE_DIR}/../External/macports/ffmpeg_5.1.2_6/lib/libswresample.a"
"${PROJECT_SOURCE_DIR}/../External/macports/ffmpeg_5.1.2_6/lib/libswscale.a"
)
The program builds (reaches 100%) but fails at linking with the following errors:
Linking CXX executable Build\project_wasm.html
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_frame_unref
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_packet_unref
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: avcodec_close
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: avcodec_close
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_frame_unref
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_packet_unref
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: avcodec_close
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: avcodec_close
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_malloc
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_packet_alloc
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_frame_alloc
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: avcodec_receive_frame
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: avcodec_send_packet
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_mallocz
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: swr_alloc
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_get_channel_layout_nb_channels
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_get_default_channel_layout
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_opt_set_int
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_opt_set_int
wasm-ld: error: CMakeFiles/project_wasm.dir/C_/Users/.../VideoPlayer.cpp.o: undefined symbol: av_opt_set_sample_fmt
答案1
得分: 1
Emscripten无法使用为macOS或其他操作系统构建的目标文件。 Emscripten是一个交叉编译器,您传递给它的所有目标文件和库都必须由Emscripten本身构建,或者它们必须是为wasm32-unknown-emscripten llvm目标构建的目标文件。
英文:
No, emscripten cannot use object files built for macOS, or any other operating system.
Emscripten is a cross compiler and all objects and libraries that you pass to it must be built by emscripten itself (or rather, they must be object files built for the wasm32-unknown-emscripten llvm target).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论