How to use GCC for C/C++ and CLANG for OBJC(++) in the same package

I’m trying to make imhex build on darwin and after trying to build it using either clang or gcc and neither working, I discovered the the github actions is using both at the same time, gcc for c and clang for objc. How do I do this in nix?

Old question below:


Old title: Gcc not recognizing ‘nullable’ keyword for objc

I’m trying to make imhex build on darwin, but got stuck at the error error: unknown type name 'nullable':

...
[13/191] Building OBJC object lib/external/libwolv/libs/io/CMakeFiles/libwolv-io.dir/source/io/fs_macos.m.o
FAILED: lib/external/libwolv/libs/io/CMakeFiles/libwolv-io.dir/source/io/fs_macos.m.o 
/nix/store/gjd9adkai8mj78kjqq9llrs9h3ng3p97-gcc-wrapper-12.3.0/bin/gcc -DARCH_64_BIT -DIMHEX_VERSION=\"1.30.1\" -DNDEBUG -DOS_MACOS -I/tmp/nix-build-imhex-1.30.1.drv-1/source/lib/external/libwolv/
In file included from /nix/store/5l0b8knnyih8pycqkib6c0g8amiy8g3g-apple-framework-Foundation/Library/Frameworks/Foundation.framework/Headers/NSArray.h:5,
                 from /nix/store/5l0b8knnyih8pycqkib6c0g8amiy8g3g-apple-framework-Foundation/Library/Frameworks/Foundation.framework/Headers/Foundation.h:10,
                 from /tmp/nix-build-imhex-1.30.1.drv-1/source/lib/external/libwolv/libs/io/source/io/fs_macos.m:5:
/nix/store/5l0b8knnyih8pycqkib6c0g8amiy8g3g-apple-framework-Foundation/Library/Frameworks/Foundation.framework/Headers/NSObject.h:19:21: error: unknown type name 'nullable'
   19 | - (id)copyWithZone:(nullable NSZone *)zone;
...

and I have no clue what would cause it and what to do about it. I did check that the version of gcc I used to compile it should have support for nullable in objc.

Here’s my WIP commit that gets to this point.


Edit: I think I have an idea of what my goal is after looking at the github actions for building it on macos. I tried both gcc and clang and neither worked, but the solution is apparently to use gcc for c and c++ and clang for objective C. Now I just need to figure out how to do that

1 Like

Did you make any additional progress with this? I’m running into a similar issue (and have failed to figure out similar issues in the past).

1 Like

I made some progress, but no success. In the end I just gave up and compiled it without nix.

I managed to mostly compile it by setting the CC and OBJC variables and using gccStdenv, but then I got linker errors:

Undefined symbols for architecture x86_64:
  "__ZN4llvm8demangleERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", referenced from:
      __ZNSt17_Function_handlerIFSt8optionalIN2pl4core5Token7LiteralEEPNS2_9EvaluatorERKSt6vectorIS4_SaIS4_EEEZN3hex6plugin7builtin32registerPatternLanguageFunctionsEvEUlS7_T_E1_E9_M_invokeERKSt9_
Any_dataOS7_SC_ in pl_builtin_functions.cpp.o
      __ZN3hex6plugin7builtin12_GLOBAL__N_113drawDemanglerEv in tools_entries.cpp.o
      __ZN3hex6plugin7builtin8ViewFind15drawContextMenuERNS2_10OccurrenceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in view_find.cpp.o
      __ZZN3hex6plugin7builtin8ViewFindC4EvENKUlyPKhmE1_clEyS4_m.constprop.0 in view_find.cpp.o

I also got a ton of warnings like this:

/nix/store/...-cctools-port-973.0.1/libexec/as/x86_64/as: 
  this system assembler is deprecated. Please migrate to the clang integrated assembler (`as -q').

I don’t know if those can be ignored or if they are hinting towards a real problem.


I did manage to fix some of the linker errors by telling the imhex cmake config to build some of its dependencies itself instead of using the versions from nix. I’m not sure if it’s because they were built using clang instead of gcc or if it’s because imhex requires some config setting when building them.


After some more attempts, I managed to make it compile a binary, but for some reason, the dynamic library it needed didn’t exist. That is probably a relatively easy problem to fix if one could figure out the reason for it, but that was the point at which I gave up and just compiled it without nix.

dyld: Library not loaded: /nix/store/1zasqrkzs629qjsq11xc0inn09cv2ynh-imhex-1.30.1/lib/libimhex.dylib
  Referenced from: /nix/store/1zasqrkzs629qjsq11xc0inn09cv2ynh-imhex-1.30.1/imhex
  Reason: image not found