1

I have Qt 5.6.2 installed on Ubuntu 16.04 (64-bit). My project build is successful except for my compiler (GCC 5.4) giving me this error over and over again:

fatal error: No such file or directory
... #include "some_cpp_file.moc"

The file exists in the output directory by the time this error is thrown, and Qt5 moc's the files with no error. It is interesting to note that this error only happens with the source .cpp files I am moc'ing. When I explicitly specify the output directory in the build script (Jamroot), the build is successful - however, this is impractical for the amount of projects that I need to build.

This project built successfully on Ubuntu 14.04 with Qt 4.8. I have installed Qt5 from the .run file they provide and also built the binaries from scratch, but no luck. The build system I am using is Boost.Build (b2) which I also use on Ubuntu 14.04 with Qt4.8 with no issues, a.k.a. I use the Jamroot file to control the build and not a CMake or qmake file.

How can I make the gcc compiler look in the output directory (bin/gcc-5.4/release/...) without explicitly telling it to look there? Is there some flag I need to add?

Thank you very much for your help in advance. :-)

Note: I realize that there aren't many details about the build system or anything, but I can't share many details - I am okay with any general advice or direction if you feel this question is not detailed enough for you to solve completely!

Dana
  • 81
  • 1
  • 8
  • Why are you even including the .moc file? – Nikos C. Aug 01 '17 at 12:33
  • Answer to that is [here](https://stackoverflow.com/questions/34928933/why-is-important-to-include-moc-file-at-end-of-a-qt-source-code-file) :-) – Dana Aug 01 '17 at 12:35
  • Yeah, this is why it's not a good idea to define `Q_OBJECT` classes in cpp files. I'd just stick to using .h files for that. Then you don't run into this problem (which I have no idea how to solve, since I avoid it to begin with :-P) – Nikos C. Aug 01 '17 at 12:40
  • @NikosC. Thanks for the advice :-) I will definitely follow it in the future, unfortunately this isn't code I've written all myself so I have to solve this build problem without changing the source code (I can modify the build parameters, though). – Dana Aug 01 '17 at 12:44
  • Here's a shot in the dark: Add the build directory to the include path. Something like `INCLUDEPATH += $$OUT_PWD` in your project file. – Nikos C. Aug 01 '17 at 12:48
  • Or `INCLUDEPATH += $$OUT_PWD/tmp` if the moc files are placed inside the tmp directory. – Nikos C. Aug 01 '17 at 12:51
  • @NikosC. That may work - I don't know the equivalent of $$OUT_PWD in a Jamroot file though, without explicitly defining the path. – Dana Aug 01 '17 at 13:06

0 Answers0