Search code examples
c++linkermingwlive555

Compile and use Live555 libs - Windows and MinGW (unresolved references)


I'm trying to compile Live555 libraries on Windows using MinGW. The official doesn't really specify how to do it (only with VC and Borland). I edited win32config so it says:

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

Then I run genWindowsMakefiles.cmd file, which created *.mak files in subfolders. I renamed them to Makefile and one run make in each of subfolders: UsageEnvironment, groupsock, liveMedia, BasicUsageEnvironment. This gave me *.lib files, however when I link them in my project, I get a lot of unresolved references like so:

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

and errors:

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]'

Any idea what I'm doing wrong? How can I fix it?


Solution

  • I managed to solve the issue. The undefined references comes from winsock library. It was linked when compiling live555, but I wasn't linking in in my project using live555 (I didn't know I should). Adding -lws2_32 to linking options solved the problem.

    When fiddling with compiling I also came across at undefined references to many functions with "_unwind_" keyword - the reason was incompatibility between compiler versions used in building live555 and the project.