编译和使用Live555库 - Windows和MinGW(未解析的引用)

时间:2016-06-30 09:03:41

标签: c++ linker mingw live555

我尝试使用MinGW在Windows上编译Live555库。 官方并没有真正指定如何做到这一点(仅限VC和Borland)。 我编辑了win32config所以它说:

NODEBUG=1
TARGETOS = WINNT
UI_OPTS =       $(guilflags) $(guilibsdll)
CONSOLE_UI_OPTS =       $(conlflags) $(conlibsdll)
CPU=i386

TOOLS32 =       C:\Tools\mingw491_32\bin
COMPILE_OPTS =      $(INCLUDES) $(cdebug) $(cflags) $(cvarsdll) -I. -I"$(TOOLS32)\include"
C =         c
C_COMPILER =        "$(TOOLS32)\gcc.exe"
C_FLAGS =       $(COMPILE_OPTS)
CPP =           cpp
CPLUSPLUS_COMPILER =    "$(TOOLS32)\g++.exe"
CPLUSPLUS_FLAGS =   $(COMPILE_OPTS)
OBJ =           o
LINK =          $(CXX) -o 
LIBRARY_LINK =      $(LD) -o 
LIBRARY_LINK_OPTS = $(LINK_OPTS) -r -Bstatic
LINK_OPTS =     -L.
CONSOLE_LINK_OPTS = $(LINK_OPTS_0) $(CONSOLE_UI_OPTS)
SERVICE_LINK_OPTS =     kernel32.lib advapi32.lib shell32.lib -subsystem:console,$(APPVER)
LIB_SUFFIX =        lib
LIBS_FOR_CONSOLE_APPLICATION =
LIBS_FOR_GUI_APPLICATION =
MULTIMEDIA_LIBS =   winmm.lib
EXE =           .exe
PLATFORM = Windows

rc32 = "$(TOOLS32)\bin\rc"
.rc.res:
    $(rc32) $<

然后我运行genWindowsMakefiles.cmd文件,该文件在子文件夹中创建了* .mak文件。我将它们重命名为Makefile,并在每个子文件夹中运行make:UsageEnvironment,groupsock,liveMedia,BasicUsageEnvironment。 这给了我* .lib文件,但是当我在项目中链接它们时,我得到了很多未解析的引用,如下所示:

c:/Tools/live555/libBasicUsageEnvironment.lib:BasicUsageEnvironment.cpp:(.text+0x502): undefined reference to `_imp__WSAGetLastError@0'
c:/Tools/live555/libBasicUsageEnvironment.lib:BasicTaskScheduler.cpp:(.text+0xf89): undefined reference to `_imp__closesocket@4'
c:/Tools/live555/libBasicUsageEnvironment.lib:BasicTaskScheduler.cpp:(.text+0x11ca): undefined reference to `_imp__select@20'
c:/Tools/live555/libBasicUsageEnvironment.lib:BasicTaskScheduler.cpp:(.text+0x11e1): undefined reference to `_imp__WSAGetLastError@0'
c:/Tools/live555/libBasicUsageEnvironment.lib:BasicTaskScheduler.cpp:(.text+0x147a): more undefined references to `__WSAFDIsSet@8' follow

和错误:

c:/Tools/mingw491_32/bin/../lib/gcc/i686-w64-mingw32/4.9.1/../../../../i686-w64-mingw32/bin/ld.exe: c:/Tools/live555/libgroupsock.lib: warning: COMDAT symbol '.eh_frame$_ZNK10NetAddress4dataEv' does not match section name '.eh_frame'
c:/Tools/mingw491_32/bin/../lib/gcc/i686-w64-mingw32/4.9.1/../../../../i686-w64-mingw32/bin/ld.exe: c:/Tools/live555/libliveMedia.lib: warning: COMDAT symbol '.eh_frame$_ZNK9HashTable7IsEmptyEv' does not match section name '.eh_frame'
c:/Tools/mingw491_32/bin/../lib/gcc/i686-w64-mingw32/4.9.1/../../../../i686-w64-mingw32/bin/ld.exe: c:/Tools/live555/libBasicUsageEnvironment.lib: bad reloc address 0x1c in section `.text$_ZN13DelayIntervalC1Ell[__ZN13DelayIntervalC1Ell]'

知道我做错了什么吗?我该如何解决?

2 个答案:

答案 0 :(得分:0)

MinGW更接近Unix风格的makefile,而不是尝试改编VC makefile,你应该尝试:

./genMakefiles mingw
make

答案 1 :(得分:0)

我设法解决了这个问题。未定义的引用来自winsock库。它在编译live555时被链接,但是我没有使用live555在我的项目中链接(我不知道我应该)。 将-lws2_32添加到链接选项可以解决问题。

当摆弄编译时,我也遇到了对“ _unwind _ ”关键字的许多函数的未定义引用 - 原因是在构建live555和项目时使用的编译器版本之间不兼容。