Xcode failed to emit precompiled header?

10,418

This error is about a malformed bridging header. The bridging header is a special header file which lists all Objective-C header files with classes that must be accessible from Swift code. All the bridging header definitions are precompiled in a way to be ready to use from Swift. In your case the bridging header is "Alavoc/bridge/Alavoc-Bridging-Header.h", and it includes a header for customClassViewController.h (from Alavoc/externalLib/customClass), which indicates that your fellow developer wants that customClassViewController is accessible in Swift code.

Now the confusing thing about the bridging header is that it is not recursively including everything, i.e. it just looks on the first level of definitions, and if you import something in your import that you want in Swift, you have to add it to the bridging header explicitly, or else you'll probably get a warning (or an error sometimes). Say you have #import "A.h" in the bridging header, and you have #import "B.h" inside "A.h", then you likely would have to add "B.h" to the bridging header as well.

Now in your example A = customClassViewController, and B = FMDB, and normally you would need to add FMDB to the bridging header, but the thing is that you most likely don't want exporting FMDB to Swift via your bridging header, because it is not meant for this (it is for your own objc code and not for 3rd party libs).

The solution would be to remove line 13 from your "customClassViewController.h". This would likely fix the bridging header compilation, but probably break the customClassViewController, so you need to include FMDB in "customClassViewController.m" and most likely adapt the "customClassViewController.h" to not have anything related to FMDB (or forward-declare those usages with @class X;).

If you move #import <FMDB/FMDB.h> to your implementation (.m) files and still get error: 'FMDB/FMDB.h' file not found, it is likely about FMDB path not being listed in your header search paths.

To solve the last one just include the right path in your "Header Search Paths" in Xcode build settings. Let's say FMDB is located at /Users/me/Downloads/Alavoc-ios-master/Alavoc/ASDASD/FMDB (and you have /Users/me/Downloads/Alavoc-ios-master/Alavoc/ASDASD/FMDB/FMDB.h inside), Then you need to open Xcode project settings - select your target on the left - select "Build Settings" on the top - find "Header Search Paths" setting and add /Users/me/Downloads/Alavoc-ios-master/Alavoc/ASDASD path

Share:
10,418
Admin
Author by

Admin

Updated on June 05, 2022

Comments

  • Admin
    Admin almost 2 years

    thanks in advance for the help you will give me.

    I have searched this for half a day over the internet yesterday and two hours now and I haven't found anything (more than those two links that did not help FMDatabase.h not found when using route-me library & Failed to emit precompiled header for bridging header)

    So here is my problem : I just had in hands a project that a previous developer has been working on, and when I try to launch it, here I have two errors :

    failed to emit precompiled header '/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch' for bridging header '/Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h'

    /Users/me/Downloads/Alavoc-ios-master/Alavoc/externalLib/customClass/customClassViewController.h:13:9: error: 'FMDB/FMDB.h' file not found

    There is also one fatal error wroten like this (even if I only have two errors counted, this one appears in the log above the two other ones previously described)

    fatal error: module file '/Users/me/Library/Developer/Xcode/DerivedData/ModuleCache/30E4RG2TSVLXF/Foundation-3DFYNEBRQSXST.pcm' is out of date and needs to be rebuilt: signature mismatch note: imported by '/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch' /Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h:13:9: note: in file included from /Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h:13: #import "customClassViewController.h"

    customClassViewController.h line 13 :

    #import <FMDB/FMDB.h>
    

    I guess those errors are linked. Do you have any idea where it could come from ?

    Thanks in advance for your help guys, I really appreciate it!

    Edit for battlmonster (new errors) :

    Here are the two errros (file not found (in Alavoc-Bridging-Header.h FMDB.h not found)) and failed to emit precompiled header :

    fatal error: file '/Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h' has been modified since the precompiled header '/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch' was built note: please rebuild precompiled header '/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch' /Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h:29:9: error: 'FMDB/FMDB.h' file not found

    import

        ^ 1 error generated. <unknown>:0: error: failed to emit precompiled header
    

    '/Users/me/Library/Developer/Xcode/DerivedData/Alavoc-arfzuirebtfstncdztyvgvtpcbgw/Build/Intermediates.noindex/PrecompiledHeaders/Alavoc-Bridging-Header-swift_1I75NH5N40QPS-clang_30E4RG2TSVLXF.pch' for bridging header '/Users/me/Downloads/Alavoc-ios-master/Alavoc/bridge/Alavoc-Bridging-Header.h'

    • battlmonstr
      battlmonstr about 6 years
      It'd help if you show the code of customClassViewController.h around line 13, because that's where you error says to look at.
    • Admin
      Admin about 6 years
      Thanks a lot for your answer mate! customClasshViewController.h line 13 is as follows : "#import <FMDB/FMDB.h>"
  • Admin
    Admin about 6 years
    Thanks for your help, but I don't understand now ? What should I not include in pre-compiled header?
  • Admin
    Admin about 6 years
    Thanks a lot for your answer, that made everything clear. So I commented the line 13 in customClassViewController.h and added the import <FMDB/FMDB.h> in customClassViewController.m. But there is still the error saying the file FMDB/FMDB.h is still not found, I don't get it ? Perhaps it is that that makes the failing to emit the precompiled header ? (There is still the error saying failed to emit precompiled header)
  • battlmonstr
    battlmonstr about 6 years
    If it is the same file and line, maybe you should clean and rebuild the project. If it is something new - find it.
  • Admin
    Admin about 6 years
    I cleaned the project and build again, still FMDB/FMDB.h file not found and failed to emit (I guess linked to the fact that FMDB cannot be found). Any ideas? :(
  • battlmonstr
    battlmonstr about 6 years
    Post the new error message. If you deleted the import line, it can't be the same (unless you need to delete it elsewhere).
  • Admin
    Admin about 6 years
    Okay I edited my post since I cannot post the error here (too long)
  • battlmonstr
    battlmonstr about 6 years
    It's the same error man. Figure it out yourself. It says: Alavoc-Bridging-Header.h:29:9. It means open Alavoc-Bridging-Header.h line 29, column 9.
  • Admin
    Admin about 6 years
    Because FMDB is imported in the bridging header bro... You did not tell me to remove if from there ? :(
  • Admin
    Admin about 6 years
    I commented FMDB in the bridging header, and now there is new error in LevelViewController.swift : "no such module CNNPopUpController" I cannot comment again since if I comment it everything has to bee commented one by one there will always be a new error related to the previous one commented mate.
  • battlmonstr
    battlmonstr about 6 years
    So you have fixed 2 errors and now getting a new one that's unrelated to FMDB or bridging headers. Maybe there's a chat somewhere where people can help you out.
  • Admin
    Admin about 6 years
    In customClassViewController.m there is still FMDB/FMDB.h file not found, I do not get it. Sometimes the error appears (when i'm on the view customClassViewController.m and sometimes it doesnot appear when i'm on another swift file while building the project). There is now CNNPopupController and FMDB not found. Wherever I put FMDB it is not found. But the file is clearly here in the project... It appears if i'm on the file that imports it when I launch the build. Otherwise it does not appear. Really strange...
  • cpl_maverick
    cpl_maverick about 6 years
    I do not have a clear detail right now on this too. I believe it should be as battlmonstr saids. Furthermore, the purpose of PCH is never for people to import .h for convenience. As its name, it actually import files before the compile time, which is different from importing .h. Therefore, my advice is, unless you have a very good reason that you must import those before compile time, else: 1, Use a global.h which contains everything, and import it everywhere 2, You really import what you need when you need.
  • battlmonstr
    battlmonstr about 6 years
    Oh, but that's much easier then. Just include the right path in your "Header Search Paths" in Xcode build settings. Let's say FMDB is located at /Users/me/Downloads/Alavoc-ios-master/Alavoc/ASDASD/FMDB (and you have /Users/me/Downloads/Alavoc-ios-master/Alavoc/ASDASD/FMDB/FMD‌​B.h inside), Then you need to open Xcode project settings - select your target on the left - select "Build Settings" on the top - find "Header Search Paths" setting and add /Users/me/Downloads/Alavoc-ios-master/Alavoc/ASDASD path there.
  • Admin
    Admin about 6 years
    Okay so I uncommented the lines #import FMDB that you told me to comment. I canceled all the changes I did before, I did put the correct path as you told me to do, and OMG you're a genius thank you so much. The errors concerning FMDB are GONE! Yay! :) Whatever the file I put myself on and build the project (bridging header or customClassViewController), I get no error, so YAY ! Thanks a lot :)
  • Admin
    Admin about 6 years
    But now I still have this No such module CNPPopupController that appears, I do not know why but I guess it is totally unrelated so I will make another post for that. Could you please post your comment as answer so I can vote it as the answer? Thanks in advance!
  • battlmonstr
    battlmonstr about 6 years
    Updated the answer, thanks. Yes, CNPPopupController should be a separate question.