How statically link ffmpeg with cgo correctly

Viewed 21

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.

1 Answers

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).

Related