Bug 1214605

Summary: Build failure on MinGW64
Product: [Community] Virtualization Tools Reporter: Pavel Fedin <p.fedin>
Component: libvirtAssignee: Libvirt Maintainers <libvirt-maint>
Status: CLOSED NEXTRELEASE QA Contact:
Severity: high Docs Contact:
Priority: unspecified    
Version: unspecifiedCC: eblake, mkletzan, rbalakri
Target Milestone: ---Keywords: Reopened
Target Release: ---   
Hardware: x86_64   
OS: Windows   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-04-28 15:45:23 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Pavel Fedin 2015-04-23 08:08:48 UTC
Description of problem:

 libvirt currently fails to build for 64-bit Windows because of missing index() function. First it produces a warning:
--- cut ---
util/virstring.c:1006:9: warning: implicit declaration of function 'index' [-Wimplicit-function-declaration]
         if (index(control_chars, str[i]))
         ^
--- cut ---
 but when linking it fails with "undefined symbol" error. MinGW's libc does not have deprecated index() and rindex(). The solution is to replace index() with strchr().

Version-Release number of selected component (if applicable):

 git HEAD

How reproducible:

 configure and build it natively under MinGW64

Comment 1 Eric Blake 2015-04-23 14:19:18 UTC
Fixed upstream. For issues like this, proposing the (obvious) patch to libvir-list is faster (and less hoops to jump through) than opening up a bug report, especially when the bug only affects git builds and not a released tarball.

commit 1268820a632846267b75432dc155779a716e289c
Author: Eric Blake <eblake>
Date:   Thu Apr 23 08:13:53 2015 -0600

    build: avoid obsolete index()
    
    Commit 2a530a3e5 is not portable to mingw, which intentionally
    avoids declaring the obsolete index().  See also:
    https://bugzilla.redhat.com/show_bug.cgi?id=1214605
    
    * src/util/virstring.c (virStringStripControlChars): Use strchr.
    
    Signed-off-by: Eric Blake <eblake>

Comment 2 Pavel Fedin 2015-04-24 11:39:53 UTC
 I decided to reopen it because there is additional problem affecting MinGW build. LDFLAGS definitions for all shared libraries in tests/Makefile.am miss $(MINGW_EXTRA_LDFLAGS) addon, and virnetserverclientmock_la_LDFLAGS needs also $(GNULIB_LIBS).
MINGW_EXTRA_LDFLAGS specified -no-undefined, without which building shared library fails on MinGW. The later explicitly adds gnulib, this is necessary because .dll module on Windows has to be self-contained, it cannot import anything from the executable which is importing the dll (without special tricks).
 Sorry, i cannot post patches, because i am reporting from my workplace, and according to regulations of our company i need an explicit approval to post patches. Currently it is being processed, and it can take a long time. Much longer than fixing the bug as described (reporting and discussion is OK here).

Comment 3 Eric Blake 2015-04-24 20:29:54 UTC
Normally, I'd suggest that you use a separate bug for separate issues.  But reopening is probably okay here.

Meanwhile, let me reiterate that since the issue you are seeing affects the latest libvirt.git, you'll probably  get faster response by posting on the upstream libvir-list mailing list than you will by making a BZ.

Comment 4 Martin Kletzander 2015-04-28 15:45:23 UTC
This should be fixed upstream by commits v1.2.14-324-g9dc57ce and v1.2.15-rc1-16-g922563e:

commit 9dc57ce2c49e06b206504b45d1104ac641761c57
Author:     Pavel Fedin <p.fedin>
AuthorDate: Mon Apr 27 13:40:53 2015 +0300

    Add missing linker flags for MinGW build

commit 922563e73ab5585205aba7a15ead04c458b9c02a
Author: Martin Kletzander <mkletzan>
Date:   Mon Apr 27 15:59:18 2015 +0200

    Fix building virnetserverclientmock with MinGW