• Advertisement
Sign in to follow this  

Compile mplayer's source code as dll in MinGW+MSYS environment

This topic is 2768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I try a way to compile mplayer as dll in MinGW+MSYS environment.
step 1, download source code of mplayer from http://www.mplayerhq.hu/design7/dload.html or download snapshot version http://www.mplayerhq.hu/MPlayer/releases/mplayer-export-snapshot.tar.bz2, I choice snapshot version. And uncompress it into C:\.

step 2, download MinGW+MSYS environment from http://sourceforge.net/projects/mplayer-ww/files, I download the latest version MinGW-full-20100518, and uncompress it into C:\MinGW.

step 3, create a file named autoconf, content listed below:
./configure --disable-mencoder --disable-debug --enable-runtime-cpudetection --disable-sdl --disable-pthreads --enable-static --enable-w32threads

step 4, modify c:\mplayer-export-2010-08-10\mplayer.c, find "#ifndef DISABLE_MAIN", add a line "#define DISABLE_MAIN" before it, save it.

step 5, create a file named Makefile_dll, content listed below:
include config.mak

DIRS = input libaf libao2 libass libdvdcss libdvdnav libdvdnav/vm libdvdread4 libfaad2 libmpcodecs libmpdemux libmpeg2 libvo loader loader/dmo loader/dshow mp3lib osdep stream stream/freesdp stream/librtsp stream/realrtsp tremor vidix

ALL_OBJS = $(foreach DIR, $(DIRS), $(wildcard $(DIR)/*.o))

MPLAYER_OBJS = $(wildcard *.o)

INNER_LIBS = libavformat/libavformat.a libavcodec/libavcodec.a libavcore/libavcore.a libavutil/libavutil.a libpostproc/libpostproc.a libswscale/libswscale.a

# $(EXTRALIBS) come from config.mak

# $(EXTRALIBS_MPLAYER) come from config.mak

mplayer.dll : $(OBJS_MPLAYER) $(ALL_OBJS)
dllwrap --output-lib=libmplayer.a --dllname=$@ --driver-name=gcc --export-all-symbols $(MPLAYER_OBJS) $(ALL_OBJS) $(INNER_LIBS) $(OTHER_LIBS) $(LIBS)

step 6, run C:\MinGW\msys.bat, do commands like below:
$cd /c/mplayer-export-2010-08-10
$make -f Makefile_dll

after follow those steps, you will get mplayer.dll and libmplayer.a two files under c:\mplayer-export-2010-08-10.

now, we can write test code in CodeBlocks and VS2008.
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

typedef int (*exp_lib_main)(int argc, char* argv[]);

int main(int argc, char* argv[])
// load library
HMODULE hModule = LoadLibrary("mplayer.dll");
return 0;

exp_lib_main _lib_main = (exp_lib_main)GetProcAddress(hModule, "lib_main");

char* prog_name = "mplayer";
char* file_name = "d:\\music\\01.mp3";

int _argc = 2;
char* _argv[] = {prog_name, file_name};
_lib_main(_argc, _argv);

return 0;
When I run code, executable target which compiled in CodeBlocks can run rightly, but in VS2008 is not right. why?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement