tgmath.h doesn't work if modules are enabled

IosObjective CMacosLlvm Clang

Ios Problem Overview


I looked into using tgmath.h to deal with the CGFloat typedef float/double mess when dealing with arm64.

This answer has a pretty good description of how to use it, except that it didn't work at all for me. No matter what, my code was still calling the math.h functions.

After spending some time looking at all of the project compiler settings, I found that disabling the "Modules" feature (https://stackoverflow.com/questions/18947516/import-vs-import-ios-7) makes it all work. More specifically, the option in the project settings is called Enable Modules(C and Objective-C) in the Apple LLVM 5.1 - Language - Modules dropdown.

To see a quick example of this issue, download a project that uses tgmath, such as MBProgressHUD, and see what happens when you enable the modules project setting. The tgmath.h calls get replaced with regular math.h calls.

My question is:

  1. Why do modules prevent tgmath from being imported properly?

  2. Is there a way to get around it and use both tgmath and modules? I would like to still be able to use them.

Ios Solutions


Solution 1 - Ios

I'm not sure what's causing the issue, but as a workaround you could at least disable modules for only the file(s) where you're using tgmath.h:

  • Navigate to the target's Build Phases tab in Xcode.
  • Under the Compile Sources phase, locate the source files.
  • Double-click the source file and type -fno-modules in the Compiler Flags popover to disable Clang modules for that file.

At least this way you would still get the benefits of modules in most of your project. (This is assuming, of course, you don't need tgmath.h in the majority of your source files.)

Solution 2 - Ios

It might already be in your math library under the name ctgmath: Link

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDimaView Question on Stackoverflow
Solution 1 - IosAdam SharpView Answer on Stackoverflow
Solution 2 - IosdammkewlView Answer on Stackoverflow