Skip to main content
GameDev.net gamedev.net
🔒 Locked 🤖 Godot

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

Started by jackyxin li Aug 26, 2010 at 3:38 AM 0 replies 2.8k views
Original Post
jackyxin li
jackyxin li
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
OTHER_LIBS = $(EXTRALIBS)

# $(EXTRALIBS_MPLAYER) come from config.mak
LIBS = $(EXTRALIBS_MPLAYER)

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
$./autoconf
$make
$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
#include
#include

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

int main(int argc, char* argv[])
{
// load library
HMODULE hModule = LoadLibrary("mplayer.dll");
if(!hModule)
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);

FreeLibrary(hModule);
system("pause");
return 0;
}
--------------------------------------------------------------------------------------------------
When I run code, executable target which compiled in CodeBlocks can run rightly, but in VS2008 is not right. why?
Endurion
Endurion
In Visual Studio the current working directory is set as the project location. Check if the call to LoadLibrary fails.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.