Best way to build MuseScore 2.1 as debug - reduce-relocation error failure only in debug not release

• Jan 27, 2017 - 01:12

I want to look at modifying some of Musescore for a personal project. Because my eventual target (Raspberry Pi 3B) does not have later QT's, I decided to build QT 5.8 from source on x64 Linux (not Pi, yet), but am having issues getting Musescore to build against it for debug.

I have a QT 5.8 version built that seems to work (at least a non-Musescore project I have builds and runs fine). I also built qtcreator and it seems to work. I have been trying to build MuseScore and hitting some issues, and have narrowed them down but not completely. I am using the instructions here to try to get MuseScore into qtcreator.

I am building 2.1 as I understand the current master is unstable.

If I build using just "make" I can get it to build. That defaults to a release build at the target "release". "make release" also builds correctly. The resulting image will run just fine (in place, I have not tried to install; musescore from a distro is not on this system at all).

The instructions for method two (at the above link) suggest using "installdebug" as a target. If I try that (from the command line or qtcreator), it fails. It also fails with "make debug". The failure is as follows:

In file included from /usr/include/QtCore/QtCore:4:0,
                 from /usr/include/QtGui/QtGuiDepends:3,
                 from /usr/include/QtGui/QtGui:3,
                 from all.h:32:
/usr/include/QtCore/qglobal.h:1097:4: error: #error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (-fPIE is not enough)."
 #  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
    ^

I have tried tracking down everything I can find, and it all looks like the cmake setup should be using -fPIC as appropriate. From what I read the reduce-relocations is the appropriate way to build qt.

And Musescore does correctly compile (presumably with -fPIC) in release, just not debug mode. I've tried running with trace and cannot find the issue (I am relatively new to linux and cmake and make).

Clearly I'd prefer a debug build if I'm going to try changing it. And since 2.1 is considered fairly stable I would have thought it would build properly, so this may be related to my qt build. Or maybe 2.1 doesn't build "debug"? I have too many "new" things to consider being at fault.

Anyone have any idea what I may be missing?

Maybe more to the point, in 2.1, should a debug build actually work with qt built with reduce-relocaiton (and potentially a 5.8 build of qt)?

My testing is on Linux, 64 bit, Ubuntu 16.04.01 LTS desktop, running in a HyperV VM.

Is there a better way to get MuseScore in qtcreator? I tried method one on the latest qtcreator, and made no progress at all, there's no prompt as the doc indicates, forcing it into the cmake command line just does nothing when built. I've never used qtcreator on a cmake project so I am not sure what to expect, maybe 5.8 is different from what the doc was written for in option 1.

Oh... for a .pro project file. :)

Any help appreciated.

Linwood


Comments

I actually think I figured this out, and it looks like a bug to me.

In the MakeList.txt that's in version 2.1 is this section:

if (APPLE)
   set(CMAKE_CXX_FLAGS_DEBUG   "-std=c++11 -fPIC -stdlib=libc++ -g -Wno-inconsistent-missing-override")
   set(CMAKE_CXX_FLAGS_RELEASE "-std=c++11 -fPIC -stdlib=libc++ -O2 -DNDEBUG -DQT_NO_DEBUG -Wno-inconsistent-missing$
else (APPLE)
   if (MINGW)
      # -mno-ms-bitfields see #22048
      set(CMAKE_CXX_FLAGS_DEBUG   "-std=c++11 -mno-ms-bitfields -g")
      set(CMAKE_CXX_FLAGS_RELEASE "-std=c++11 -mno-ms-bitfields -O2 -DNDEBUG -DQT_NO_DEBUG")
      set(CMAKE_EXE_LINKER_FLAGS "-Wl,--large-address-aware")
   else (MINGW)
      set(CMAKE_CXX_FLAGS_DEBUG   "-std=c++11 -fPIC -fPIE -g")
      set(CMAKE_CXX_FLAGS_RELEASE "-std=c++11 -fPIC -O2 -DNDEBUG -DQT_NO_DEBUG")
   endif (MINGW)
endif(APPLE)

Notice that for linux it is going to use both -fPIC and -fPIE. I think that's OK from a compilation standpoint, but here's the code in version 5.8 of QT's header qglobal.h:

#if !defined(QT_BOOTSTRAPPED) && defined(QT_REDUCE_RELOCATIONS) && defined(__ELF__) && \
    (!defined(__PIC__) || (defined(__PIE__) && defined(Q_CC_GNU) && Q_CC_GNU >= 500))
#  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
         "Compile your code with -fPIC (-fPIE is not enough)."
#endif

Notice that with the compiler GNU > 500, if BOTh the PIE and PIC are defined, this gives an error.

Assuming the qglobal.h is correct (or more precisely not something easily changed), it would seem that the v2.1 CMakeLists.txt should be changed to remove the -fPIE?

I haven't tried to see if this was introduced in 5.8 or was always there, or maybe no one builds a regular debug build?

MuseScore 2.1 requires Qt 5.4 (at least on Windows, not realy sure about other platforms, WebView is the missing component in later Qt versions where it got replaced by WebEngine, IIRC), master needs at least 5.6 but should work with 5.8 too.

That code in qglobal.h is in Qt-5.4 too

That -fPIE is gone from CMakeLists.txt in master, since 6f2cf4c, to fix build for gcc 5.2. So yes, it should go from 2.1 too I guess. Not sure though whether it then still works for older GCC versions, and which normally is being used to to build 2.1 on Linux?

I just tried building MuseScore 2.1 branch on Ubuntu 16.10 and ran into this error. Removing -fPIE fixed it for me too.

In reply to by shoogle

Sounds like it is already fixed in later versions, so I guess no point in posting an issue. I guess I should have pulled down a master clone and looked (though until I found it, I really did not know what I was looking for).

Thanks for the followup.

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