[SOLVED] How statically link ffmpeg with cgo correctly

Issue

This Content is from Stack Overflow. Question asked by ryoii

I am making a ffmpeg program with cgo. I wanna statically link ffmpeg into the program.

I write these in cgo

/*
#cgo CFLAGS: -g -Wall -I./include
#cgo LDFLAGS: -L${SRCDIR}/lib -llibavformat  -llibavcodec -llibavutil -llibavdevice -llibavfilter -llibswresample -llibswscale

#include "ffmpeg.h"
*/
import "C"

It builds successfully. But it will report “mssing avxxx.dll” while running. I guess it is compiled via dynamic linking.



Solution

I believe the first comment on this prior question has your answer: How to link ffmpeg statically using mingw?

Essentially, you have to have the static version of libffmpeg and -static in the CFLAGS. The bad news is that is looks like libffmpeg does not ship with static libraries so you may have to build it yourself (read the lower comments in that answer).


This Question was asked in StackOverflow by ryoii and Answered by Liam Kelly It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?