Compiling from Source (f83f8b9), Ubuntu 12.04, Qt 5.2, Requiring -fPIC for PCH all.h

• Apr 5, 2014 - 19:37

Hello,

I am attempting to build Musescore from source. I was able to follow the instructions for the most part, but I had to modify a few things:

I installed gcc-4.8, but I am doing development on other things that I do not wish to interfere with, so I made my own 'atlernatives' folder.

#!/bin/bash

mkcd () { mkdir "$@" && cd "${!#}"; } # Separate arguments so that -p can be used
# Symlinks into custom alternatives
mkcd -p ~/local/bin/alternatives
ln -s /usr/bin/g*-4.8 .
rename 's#(.*)-4.8#$1#g' *

# Update environment variables
export PATH=~/local/lib/Qt-5.2/5.2.1/gcc_64:~/local/bin/alternatives:$PATH

# Install additional dependencies
sudo apt-get install libsndfile1-dev
sudo apt-get install libjack-jackd2-dev # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=695550
# Use y-ppa-manager to fix any missing GPG keys

# Configure cmake
cd ~/devel/third/MuseScore
mkcd -p build.release
cmake .. -DCMAKE_CXX_COMPILER=$(which g++) -DCMAKE_C_COMPILER=$(which gcc)

I am able to run CMake where the only warning is: "optional package portaudio-2.0 Version 19 not found (package portaudio19-dev)"

Once I try to build, I dies when compiling the PCH "all.h", with Qt 5.2 invoking an #error because of an -fPIC flag: (trimming output via regex: "s/-I(.*?)\s(?=-)//g")

$ make VERBOSE=1
Generating all.h.gch
[ 0%] /home/eacousineau/local/bin/alternatives/g++ -x c++-header -g -DQT_DISABLE_DEPRECATED_BEFORE=0 -DQT_DISABLE_DEPRECATED_BEFORE=0 -o all.h.gch all.h
Built target genManual
In file included from /home/eacousineau/local/lib/Qt-5.2/5.2.1/gcc_64/include/QtCore/qnamespace.h:45:0,
from /home/eacousineau/local/lib/Qt-5.2/5.2.1/gcc_64/include/QtCore/qobjectdefs.h:45,
from /home/eacousineau/local/lib/Qt-5.2/5.2.1/gcc_64/include/QtCore/qobject.h:48,
from /home/eacousineau/local/lib/Qt-5.2/5.2.1/gcc_64/include/QtCore/qabstractanimation.h:45,
from /home/eacousineau/local/lib/Qt-5.2/5.2.1/gcc_64/include/QtCore/QtCore:4,
from /home/eacousineau/local/lib/Qt-5.2/5.2.1/gcc_64/include/QtGui/QtGuiDepends:2,
from /home/eacousineau/local/lib/Qt-5.2/5.2.1/gcc_64/include/QtGui/QtGui:3,
from all.h:32:
/home/eacousineau/local/lib/Qt-5.2/5.2.1/gcc_64/include/QtCore/qglobal.h:1008:4: error: #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. "\
^
make[2]: *** [all.h.gch] Error 1

I tried going through and haphazardly adding -fPIC flags in (see patch here), but I could not get the flag to appear...

(For those who wish to reproduce these results, I tried finding the right locations by searching and opening the files)

find . -path '*/build*' -prune -o \( -name 'CMakeLists.txt' -o -name '*.cmake' \) -print | xargs grep 'PCH_INCLUDE' --color -nom1 | xargs sublime -n

Does anybody have some suggestions on how I might resolve this?
Thanks!
- Eric


Comments

Rather than chase your tail with more errors or risk messing up any of your other projects, might it be worth creating a new partition complete with its own OS and QT version just to play with MuseScore builds in? You could even use it as an excuse to try out Tangy Targ or whatever it's called.

In reply to by underquark

It is actually worth more for me to dig a little bit because I am actually interested in the development part of the project as well. This has been a good exercise in CMake for me because I use this for my research.

Regarding messing with other projects, given the isolation the Linux provides with environment variables and the Debian's packaging conventions, I am 98% confident that I won't mess up my other projects. However, there's always a chance haha.

Thank you for the suggestion though! (And I looked it up, and it was actually Trusty Tahr, some goat-like thing... Tasty Targ would have been a much more awesome name)

-fPIC or -fPIE are added to the compile flags on this line

It seems the precompiled header creation doesn't consider this setting for your environment. The precompiled header generation is in CreatePrecompiledHeader included here
and called here .

CreatePrecompiledHeader.cmake is where the magic should happen. You could try to add some debugging information in this file to find out why the compile flags are not used.

In reply to by [DELETED] 5

Ah, that helped a ton! It was because when I configured CMake, I had not specified a CMAKE_BUILD_TYPE (I didn't look at the Makefile closely enough haha), so in the code ${CMAKE_BUILD_TYPE} expanded to nothing, which caused ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}} to expand to nothing as well.

Adding -DCMAKE_BUILD_TYPE=RELEASE makes it compile, and I'm running the build now.

Thanks!

Do you still have an unanswered question? Please log in first to post your question.