[Development] Qt-5.1, qglobal.h and PIC detection

Christian Gagneraud chgans at gna.org
Wed Nov 6 01:51:37 CET 2013

On 06/11/13 12:25, Olivier Goffart wrote:
> On Wednesday 06 November 2013 12:17:56 Christian Gagneraud wrote:
>> Hi,
>> I'm using CLang build-analize tool, and when I switched from Qt 4.8 to
>> Qt 5.1 (insalled from Qt project's download area), I got a Qt #error,
>> basically the code is built with -fPIC, but CLang doesn't define a PIC
>> macro, so the build fails due to a check in qglobal.h (see details below).
>> Is it possible to use CLang 3.2 with Qt 5.1 on Linux, or do I need to
>> use amore recent verion of CLang or maybe wait for Qt 5.2?
> Simply add -fPIC or -fPIE.
> clang -fPIE -dM -E -x c /dev/null |grep -i 'PIC\|PIE\|ELF'
> #define __ELF__ 1
> #define __PIC__ 2
> #define __PIE__ 2
> #define __pic__ 2
> #define __pie__ 2

Good point, it works here as well, but I still have the error when 
building my code, scan-build replace the calls to g++ by clang++ (using 
CXX=clamg++), but the -fPIC get lost somewhere...
To get it working, I have to do:
$ scan-build 'make CC=${CC} CXX=${CXX}'

So maybe, i'm not using it correctly

While debugging, here is the output of scan-build:

$ scan-build -v -v -v 'make CC=${CC} CXX=${CXX}'
scan-build: Using '/usr/bin/clang' for static analysis
scan-build: Emitting reports for this run to '/tmp/scan-build-2013-11-06-7'.
/usr/share/clang/scan-build/c++-analyzer -c -pipe -O2 -Wall -W 
-DQT_CORE_LIB -I/opt/lambda/2013.10/5.1.1/gcc/mkspecs/linux-g++ -I. 
-I/opt/lambda/2013.10/5.1.1/gcc/include/QtCore -I. -o fileutils.o 
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DUTILS_LIBRARY 
-I/opt/lambda/2013.10/5.1.1/gcc/mkspecs/linux-g++ -I. 
-I/opt/lambda/2013.10/5.1.1/gcc/include/QtCore -I. -o fileutils.o 

[LOCATION]: /home/christiaga/projects/lambda-simulator/utils
#SHELL (cd '/home/christiaga/projects/lambda-simulator/utils' && 
'/usr/bin/clang++' '-cc1' '-triple' 'i386-pc-linux-gnu' '-analyze' 
'-disable-free' '-disable-llvm-verifier' '-main-file-name' 
'fileutils.cpp' '-analyzer-store=region' 
'-analyzer-opt-analyze-nested-blocks' '-analyzer-eagerly-assume' 
'-analyzer-checker=core' '-analyzer-checker=unix' 
'-analyzer-checker=security.insecureAPI.vfork' '-analyzer-output' 
'plist' '-w' '-mrelocation-model' 'static' '-mdisable-fp-elim' 
'-fmath-errno' '-masm-verbose' '-mconstructor-aliases' 
'-fuse-init-array' '-target-cpu' 'pentium4' '-target-linker-version' 
'2.23.2' '-momit-leaf-frame-pointer' '-resource-dir' 
'/usr/bin/../lib/clang/3.2' '-D' '_REENTRANT' '-D' 'UTILS_LIBRARY' '-D' 
'/opt/lambda/2013.10/5.1.1/gcc/mkspecs/linux-g++' '-I' '.' '-I' 
'/opt/lambda/2013.10/5.1.1/gcc/include' '-I' 
'/opt/lambda/2013.10/5.1.1/gcc/include/QtXml' '-I' 
'/opt/lambda/2013.10/5.1.1/gcc/include/QtCore' '-I' '.' 
'-fmodule-cache-path' '/var/tmp/clang-module-cache' '-internal-isystem' 
'/usr/bin/../lib/gcc/i686-linux-gnu/4.7/../../../../include/c++/backward' '-internal-isystem' 
'/usr/local/include' '-internal-isystem' 
'/usr/bin/../lib/clang/3.2/include' '-internal-isystem' 
'/usr/include/clang/3.2/include/' '-internal-externc-isystem' 
'/usr/include/i386-linux-gnu' '-internal-externc-isystem' 
'/usr/include/i686-linux-gnu' '-internal-externc-isystem' '/usr/include' 
'-fdeprecated-macro' '-fdebug-compilation-dir' 
'/home/christiaga/projects/lambda-simulator/utils' '-ferror-limit' '19' 
'-fmessage-length' '0' '-mstackrealign' '-fobjc-runtime=gcc' 
'-fcxx-exceptions' '-fexceptions' '-fdiagnostics-show-option' 
'-analyzer-display-progress' '-analyzer-output=html' '-o' 
'/tmp/scan-build-2013-11-06-7' '-x' 'c++' 'fileutils.cpp')
In file included from fileutils.cpp:30:
In file included from ./fileutils.h:33:
In file included from ./utils_global.h:4:
/opt/lambda/2013.10/5.1.1/gcc/include/QtCore/qglobal.h:975:4: error: 
"You must build your code with position independent code if Qt was built 
with -reduce-relocations. "         "Compile your code with -fPIC or -fPIE."
#  error "You must build your code with position independent code if Qt 
was built with -reduce-relocations. "\

Sorry for all the garbage, but it shows that clang++ is called without 
the -fPIC, so it might be a bug in the version a clang I'm using, or i'm 
missing something.
The single quote and the CXX=${CXX} stuff is to force make to call 
${CXX} when building an object, CXX is set by scan-build to 
"/usr/share/clang/scan-build/ccc-analyzer" (a perl script), which in 
turn call g++ to build the file and clang++ for the analysis...

calling "scan-build 'make CC=${CC} CXX=${CXX}'" is the only solution I 
found to be able to use scan-build with Makefiles generated by qmake, If 
anyone knows a more elegant solution, can you please let me know?


More information about the Development mailing list