Wireshark-bugs: [Wireshark-bugs] [Bug 11643] build error on Debian testing: Couldn't compile Qt
Comment # 12
on bug 11643
from Guy Harris
(In reply to Peter Wu from comment #10)
> Does removal of the broken check in https://code.wireshark.org/review/11618
> fix your build?
It fixes the build on my Ubuntu 15.10 VM, which has Qt 5.4.2, rather than the
Qt 5.5.0 that adds -fPIC even for MSVC:
https://bugreports.qt.io/browse/QTBUG-47942
and it causes wireshark-qt.cpp to be built with command line arguments that
include -fPIC, -fPIE, and -fPIC, in that order.
The current unmodified CMakeLists.txt test fails to build with -fPIC on that
platform; it builds with -fPIC and -fPIE, in that order, and the test fails
with the "You must build your code with position independent code if Qt was
built with -reduce-relocations." error.
This suggests that you can, at least with that version of GCC:
$ g++ --version
g++ (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010
compile with both -fPIC and -fPIE specified, and that the *last* such option
specified applies.
I.e., if you're going to compile any code that uses Qt, you must ensure that
-fPIC comes *after* any -fPIE that's either explicitly inserted by the build
scripts or inserted by CMake as a result of setting a property.
You must also ensure that you use neither -fPIC nor -fPIE with a compiler that
doesn't support it; this includes MSVC, but may also include the C++ compiler
that comes with Oracle Studio 11 through 12.4 (they use -Kpic/-KPIC, and
neither the documentation for 11 nor the documentation for 12.4 mentions -fpic
or -fPIC), HP's C++ compiler (which has no mention of -fPIC in its
documentation), and IBM XL C/C++ version 13.1.2 (they use -qpic, and the
documentation doesn't mention -fpic or -fPIC).
So, unless either
1) those compilers all accept -fPIC but don't document it
or
2) Qt 5.5.0's CMake files avoid adding -fPIC for those compilers even
though they add it for MSVC
removing -fPIC only for MSVC is an error.
The offending conditional in the Qt 5.5.0 headers is:
#if !defined(QT_BOOTSTRAPPED) && defined(QT_REDUCE_RELOCATIONS) &&
defined(__ELF__) && \
(!defined(__PIC__) || (defined(__PIE__) && defined(Q_CC_GNU) && Q_CC_GNU >=
500))
so it appears that you don't need -fPIC if:
1) your object file format isn't ELF (so -fPIC shouldn't be needed on
Windows, OS X, or AIX, none of which use ELF);
2) you're building -fPIE with a compiler for which Q_CC_GNU is defined and
is >= 500.
>From a quick look at Qt 5.5.0's qcompilerdetection.h, Q_CC_GNU will be defined
if the compiler defines __GNUC__, so it will be set for Clang and Intel C, so
the only things that would save you from getting hit by that if you're using
Clang or Intel C on a platform using ELF are:
1) the compiler in question setting __GNUC__ to a value <= 4
or
2) -reduce-relocations not being used for Qt on your platform
so I'm not sure I'd want to rely on "remove -fPIC if the compiler isn't GCC".
You are receiving this mail because:
- You are watching all bug changes.