Need some help with nix for macos

Hi! I hope I’m writing in the correct section. I’ve been given a mac for my work and I’m trying to configure it. What I’m trying to do is to have gazebo running, step by step.

This is going to be a specific macos question about a command not found.

Right now I’m trying to make an apple version for the ogre3d package, and I’m willing to merge it into mainstream when is finished. I’m almost finished, but at the end of the compilation, I get the error

/bin/sh: ditto: command not found

I’ve tried many times but I cannot find the proper nix package that includes ditto. Do you have any ideas where I can find it?

Cheers

I would suggest you try nix-index. It is a nice tool to search for anything that lands in the output of any derivations.

unfortunately ditto is one of those commands that Apple has never released the source code for. ditto is used rarely enough that we have been able to get away with not having it for the most part. However, it looks like ogre3d uses ditto pretty extensively. Perhaps we can make a fake wrapper for it. I think it is pretty close to rsync and perhaps that would work? You can try something like this:

{ writeScriptBin, stdenv }:

let ditto = writeScriptBin "ditto" ''
#!${stdenv.shell}
rsync "$@"
''; in

stdenv.mkDerivation {
  ...
  nativeBuildInputs = [ ... ditto ... ];
  ...
}

With maybe some added logic if needed.

Another thing to try would be to replace “ditto” commands in ogre3d with “/usr/bin/ditto”. It’s impure but in this case might be acceptable as a quick fix.

2 Likes

Thanks!
right now I’ll use an hack, to minimize the variables. As soon as I have a Minimal Viable Product, I’ll try with rsync instead.


let ditto = writeScriptBin "ditto" ''
#!${stdenv.shell}
/usr/bin/ditto "$@"
''; in

stdenv.mkDerivation {
  ...
  nativeBuildInputs = [ ... ditto ... ];
  ...
}

Now, if I may still ask, I get this error:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_NSArray", referenced from:
      objc-class-ref in OgreOSXConfigDialog.mm.o
  "_OBJC_CLASS_$_NSDictionary", referenced from:
      objc-class-ref in OgreOSXConfigDialog.mm.o
  "_OBJC_CLASS_$_NSMutableArray", referenced from:
      objc-class-ref in OgreOSXConfigDialog.mm.o
ld: symbol(s) not found for architecture x86_64

togheter with a lot of warnings about DEPLOYMENT_RUNTIME_SWIFT being undefined.

/nix/store/pdhxr5a7qqqq8ld64ahfapn8kv8gn48i-swift-corefoundation-private/Library/Frameworks/CoreFoundation.framework/Headers/CFString.h:154:5: warning: 'DEPLOYMENT_RUNTIME_SWIFT' is not defined, evaluates to 0 [-Wundef]
#if DEPLOYMENT_RUNTIME_SWIFT

I understood that you want to define DEPLOYMENT_RUNTIME_SWIFT when you are using the open source version of swift and undefine it if you want the OBJECTIVE_C runtime for swift. I even wonder if I really need this at all…

Anyway, do you have any idea what am I doing wrong with this core foundation framework?

The DEPLOYMENT_RUNTIME_SWIFT can probably be ignored. You could add something like NIX_CFLAGS_COMPILE="-DDEPLOYMENT_RUNTIME_SWIFT=0"; to fix the warning (no difference in code generation though).

You might need -lobjc to fix the undefined symbol error. It should be available from darwin.objc4. You can do this with:

NIX_LDFLAGS="-lobjc";

I don’t know why that’s not included by default though.

Nice, but it doesn’t seem to work :frowning:

running cmake/make in verbouse mode, I discovered this is the compiler command that makes the error:

[ 73%] Linking CXX shared library ../../lib/macosx/OgreBites.framework/OgreBites
cd /Users/matteo/projects/nix_packages/ogre3d/ogre-1.11.2/build/Components/Bites && /nix/store/43968xcg2c5h0s2f180zklm8560xqpys-cmake-3.12.1/bin/cmake -E cmake_link_script CMakeFiles/OgreBites.dir/link.txt --verbose=1
/nix/store/6mca864ajrir4d7j0aka53pvh2p7vdaq-clang-wrapper-5.0.2/bin/clang++ -Wall -Winit-self -Wcast-qual -Wwrite-strings -Wextra -Wundef -Wmissing-declarations -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers -Wno-long-long  -msse -O3 -DNDEBUG -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -compatibility_version 1.11.2 -current_version 1.11.2 -o ../../lib/macosx/OgreBites.framework/Versions/1.11.2/OgreBites -install_name @executable_path/../Frameworks/OgreBites.framework/Versions/1.11.2/OgreBites CMakeFiles/OgreBites.dir/src/OgreAdvancedRenderControls.cpp.o CMakeFiles/OgreBites.dir/src/OgreApplicationContext.cpp.o CMakeFiles/OgreBites.dir/src/OgreBitesConfigDialog.cpp.o CMakeFiles/OgreBites.dir/src/OgreCameraMan.cpp.o CMakeFiles/OgreBites.dir/src/OgreSGTechniqueResolverListener.cpp.o CMakeFiles/OgreBites.dir/src/OgreStaticPluginLoader.cpp.o CMakeFiles/OgreBites.dir/src/OgreTrays.cpp.o CMakeFiles/OgreBites.dir/src/OgreWindowEventUtilities.cpp.o CMakeFiles/OgreBites.dir/src/OgreOSXConfigDialog.mm.o -Wl,-rpath,/nix/store/fjmpj7c7mzlsii60n83j6nbmc4mpk8kq-ogre3d-1.11.2/lib ../../lib/macosx/OgreOverlay.framework/Versions/1.11.2/OgreOverlay -framework Cocoa ../../lib/macosx/OgreRTShaderSystem.framework/Versions/1.11.2/OgreRTShaderSystem /nix/store/jr4xk3vnibpam36yc71ba99iqnc2jj95-SDL2-2.0.8-dev/lib/libSDL2main.a /nix/store/1jxwxgdgk9967pzyhis9zqdyv6n26s38-SDL2-2.0.8/lib/libSDL2.dylib -framework Cocoa /nix/store/jr4xk3vnibpam36yc71ba99iqnc2jj95-SDL2-2.0.8-dev/lib/libSDL2main.a /nix/store/1jxwxgdgk9967pzyhis9zqdyv6n26s38-SDL2-2.0.8/lib/libSDL2.dylib ../../lib/macosx/Ogre.framework/Versions/1.11.2/Ogre 
Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_NSArray", referenced from:
      objc-class-ref in OgreOSXConfigDialog.mm.o
  "_OBJC_CLASS_$_NSDictionary", referenced from:
      objc-class-ref in OgreOSXConfigDialog.mm.o
  "_OBJC_CLASS_$_NSMutableArray", referenced from:
      objc-class-ref in OgreOSXConfigDialog.mm.o
ld: symbol(s) not found for architecture x86_64
clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)

I tried manually adding -lobjc in the command and to use NIX_LDFLAGS="-lobjc"; but the error stays the same.

(the other hack with NIX_CFLAGS_COMPILE worked very well, now I understand what the output is about, thanks)

If you have any other ideas, they are welcome. I’ll keep experimenting until I get it running.

@portaloffreedom I get a similar linking error when packaging OpenCV-4.0.0 for OS X. Did you ever fix this error?

@matthewbauer any ideas how to fix my linking error in PR #51027?

@basvandijk No, I haven’t
I’m still stuck…

Try adding a dependency on darwin.cf-private. This comment explains why a bit.

@basvandijk I think this should fix your issue too.

@basvandijk I see you’ve reported the failure upstream. If adding cf-private fixes it, it’s probably a Nix-specific issue, since the way Nix splits apart frameworks and stuff is kind of specific to it. If you were building using Apple’s CLT or Xcode you probably wouldn’t have the issue.

@qyliss great tip, thank you! Currently trying this out.

@qyliss the build succeeds on my system. TIL about cf-private. Thank you very much!

@qyliss THANK YOU! I already tried it but I was mixing it with other versions of CF and that’s probably why I couldn’t make it work.

I still have some problems liking AGL, but it seems a problem of the source CMakeFile.txt that I can quickly fix using sed. I will make a pull request on the main repo once I finish it so others can install ogre on their OSX using nix.

Cheers everyone :slight_smile: