Skip to contentSkip to conversation

configure: check that C++ compiler actually works

PATCH In review Peter Maydell 3 participants 4 messages Feb 20, 2014 – Feb 24, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 configure: check that C++ compiler actually works

Check that the C++ compiler works with the C compiler; if it does not, then don't pass CXX to the build process. This fixes a regression where QEMU was no longer building if the build environment didn't have a C++ compiler (introduced in commit 3144f78b, which incorrectly assumed that rules.mak would only see a non-empty $(CXX) if configure had actually found a working C++ compiler).

---
Apologies for the breakage for people who were building in setups with no C++ compiler -- I should have tested the original change more thoroughly.

 configure | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
configure +29 -0
index 4648117..6829cbb 100755
@@ -1289,6 +1289,35 @@ else
     error_exit "\"$cc\" either does not exist or does not work"
 fi
 
+# Check that the C++ compiler exists and works with the C compiler
+if has $cxx; then
+    cat > $TMPC <<EOF
+int c_function(void);
+int main(void) { return c_function(); }
+EOF
+
+    compile_object
+
+    cat > $TMPC <<EOF
+extern "C" {
+   int c_function(void);
+}
+int c_function(void) { return 42; }
+EOF
+
+    if (cc=$cxx do_cc $QEMU_CFLAGS -o $TMPE $TMPC $TMPO $LDFLAGS); then
+        # C++ compiler $cxx works ok with C compiler $cc
+        :
+    else
+        echo "C++ compiler $cxx does not work with C compiler $cc"
+        echo "Disabling C++ specific optional code"
+        cxx=
+    fi
+else
+    echo "No C++ compiler available; disabling C++ specific optional code"
+    cxx=
+fi
+
 # Consult white-list to determine whether to enable werror
 # by default.  Only enable by default for git builds
 z_version=`cut -f3 -d. $source_path/VERSION`
Signature · 1 line
1.8.5
Tested-by on v1 1/1
#1 lore raw
Quoted 49 lines · On Thu, 20 Feb 2014 15:10:16 +0000 Peter Maydell <[email protected]>…

Check that the C++ compiler works with the C compiler; if it does not, then don't pass CXX to the build process. This fixes a regression where QEMU was no longer building if the build environment didn't have a C++ compiler (introduced in commit 3144f78b, which incorrectly assumed that rules.mak would only see a non-empty $(CXX) if configure had actually found a working C++ compiler).

---
Apologies for the breakage for people who were building in setups with no C++ compiler -- I should have tested the original change more thoroughly.

 configure | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
configure +22 -0
index 4648117..6829cbb 100755
@@ -1289,6 +1289,35 @@ else
     error_exit "\"$cc\" either does not exist or does not work"
 fi
 
+# Check that the C++ compiler exists and works with the C compiler
+if has $cxx; then
+    cat > $TMPC <<EOF
+int c_function(void);
+int main(void) { return c_function(); }
+EOF
+
+    compile_object
+
+    cat > $TMPC <<EOF
+extern "C" {
+   int c_function(void);
+}
+int c_function(void) { return 42; }
+EOF
+
+    if (cc=$cxx do_cc $QEMU_CFLAGS -o $TMPE $TMPC $TMPO $LDFLAGS); then
+        # C++ compiler $cxx works ok with C compiler $cc
+        :
+    else
+        echo "C++ compiler $cxx does not work with C compiler $cc"
+        echo "Disabling C++ specific optional code"

configure else · line 1323

Quoted 10 lines
configure +7 -0
+        cxx=
+    fi
+else
+    echo "No C++ compiler available; disabling C++ specific optional code"
+    cxx=
+fi
+
 # Consult white-list to determine whether to enable werror
 # by default.  Only enable by default for git builds
 z_version=`cut -f3 -d. $source_path/VERSION`

Works fine for me now on my system w/o C++ compiler:

#2 lore raw
Quoted 64 lines · Thomas Huth
Quoted 49 lines · On Thu, 20 Feb 2014 15:10:16 +0000 Peter Maydell <[email protected]>…

Check that the C++ compiler works with the C compiler; if it does not, then don't pass CXX to the build process. This fixes a regression where QEMU was no longer building if the build environment didn't have a C++ compiler (introduced in commit 3144f78b, which incorrectly assumed that rules.mak would only see a non-empty $(CXX) if configure had actually found a working C++ compiler).

---
Apologies for the breakage for people who were building in setups with no C++ compiler -- I should have tested the original change more thoroughly.

 configure | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
configure +22 -0
index 4648117..6829cbb 100755
@@ -1289,6 +1289,35 @@ else
     error_exit "\"$cc\" either does not exist or does not work"
 fi
 
+# Check that the C++ compiler exists and works with the C compiler
+if has $cxx; then
+    cat > $TMPC <<EOF
+int c_function(void);
+int main(void) { return c_function(); }
+EOF
+
+    compile_object
+
+    cat > $TMPC <<EOF
+extern "C" {
+   int c_function(void);
+}
+int c_function(void) { return 42; }
+EOF
+
+    if (cc=$cxx do_cc $QEMU_CFLAGS -o $TMPE $TMPC $TMPO $LDFLAGS); then
+        # C++ compiler $cxx works ok with C compiler $cc
+        :
+    else
+        echo "C++ compiler $cxx does not work with C compiler $cc"
+        echo "Disabling C++ specific optional code"

configure else · line 1323

Quoted 10 lines
configure +7 -0
+        cxx=
+    fi
+else
+    echo "No C++ compiler available; disabling C++ specific optional code"
+    cxx=
+fi
+
 # Consult white-list to determine whether to enable werror
 # by default.  Only enable by default for git builds
 z_version=`cut -f3 -d. $source_path/VERSION`

Works fine for me now on my system w/o C++ compiler:

Quoted 1 line

Works for me too, in cross environment for ppc64 on x86_64,

Thanks.

Signature · 1 line
Alexey
#3 lore raw
In reply to Peter Maydell
Quoted 8 lines · Peter Maydell

Check that the C++ compiler works with the C compiler; if it does not, then don't pass CXX to the build process. This fixes a regression where QEMU was no longer building if the build environment didn't have a C++ compiler (introduced in commit 3144f78b, which incorrectly assumed that rules.mak would only see a non-empty $(CXX) if configure had actually found a working C++ compiler).

Quoted 7 lines

---
Apologies for the breakage for people who were building in setups with no C++ compiler -- I should have tested the original change more thoroughly

Applied directly to master since it's a build-breakage fix.

thanks
-- PMM