google-deepmind / mujoco

Multi-Joint dynamics with Contact. A general purpose physics simulator.
https://mujoco.org
Apache License 2.0
7.52k stars 743 forks source link

Missing symlink to library in macOS release #313

Open coolvision opened 2 years ago

coolvision commented 2 years ago

Using:

First, tried to build with the makefile:

sks-MacBook-Pro:sample sk$ make
clang++ -O2 -F/Applications/MuJoCo.app/Contents/Frameworks -I/usr/local/include -pthread -std=c++17 -stdlib=libc++ -L/usr/local/lib -Wl,-rpath,/Applications/MuJoCo.app/Contents/Frameworks    testxml.cc    -framework mujoco        -o testxml
ld: framework not found mujoco
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1

checked that framework is installed in correct location required by the makefile:

sks-MacBook-Pro:sample sk$ ls -all /Applications/MuJoCo.app/Contents/Frameworks
total 0
drwxr-xr-x@ 3 sk  admin   96 May 20 00:19 .
drwxr-xr-x@ 8 sk  admin  256 May 20 01:02 ..
drwxr-xr-x@ 6 sk  admin  192 May 20 00:19 mujoco.framework

Clang version:

sks-MacBook-Pro:sample sk$ clang++ --version
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: x86_64-apple-darwin21.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Next, tried to run first makefile command:

sks-MacBook-Pro:sample sk$ clang++ -O2 -F/Applications/MuJoCo.app/Contents/Frameworks -I/usr/local/include -pthread -st
d=c++17 -stdlib=libc++ -L/usr/local/lib -Wl,-rpath,/Applications/MuJoCo.app/Contents/Frameworks    testxml.cc    -frame
work mujoco        -o testxml -v
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: x86_64-apple-darwin21.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx12.0.0 -Wundef-prefix=TARGET_OS_ -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name testxml.cc -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fno-strict-return -fno-rounding-math -munwind-tables -target-sdk-version=12.3 -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -debugger-tuning=lldb -target-linker-version 763 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.1.6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -F/Applications/MuJoCo.app/Contents/Frameworks -I /usr/local/include -I/usr/local/include -stdlib=libc++ -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.1.6/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -O2 -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -Wno-elaborated-enum-base -Wno-reserved-identifier -Wno-gnu-folding-constant -Wno-objc-load-method -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/Users/sk/code/mujoco_release/sample -ferror-limit 19 -pthread -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fno-cxx-modules -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcommon -fcolor-diagnostics -vectorize-loops -vectorize-slp -clang-vendor-feature=+messageToSelfInClassMethodIdReturnType -clang-vendor-feature=+disableInferNewAvailabilityFromInit -clang-vendor-feature=+disableNonDependentMemberExprInCurrentInstantiation -fno-odr-hash-protocols -clang-vendor-feature=+enableAggressiveVLAFolding -clang-vendor-feature=+revert09abecef7bbf -clang-vendor-feature=+thisNoAlignAttr -clang-vendor-feature=+thisNoNullAttr -mllvm -disable-aligned-alloc-awareness=1 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/fd/6wwmyp3j4rvc7bb74c_21y2w0000gn/T/testxml-771653.o -x c++ testxml.cc
clang -cc1 version 13.1.6 (clang-1316.0.21.2.5) default target x86_64-apple-darwin21.5.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
ignoring duplicate directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
 /Applications/MuJoCo.app/Contents/Frameworks (framework directory)
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.1.6/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch x86_64 -platform_version macos 12.0.0 12.3 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o testxml -L/usr/local/lib -L/usr/local/lib -rpath /Applications/MuJoCo.app/Contents/Frameworks /var/folders/fd/6wwmyp3j4rvc7bb74c_21y2w0000gn/T/testxml-771653.o -framework mujoco -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.1.6/lib/darwin/libclang_rt.osx.a -F/Applications/MuJoCo.app/Contents/Frameworks
ld: framework not found mujoco
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Finally was able to fix this by adding a symlink:

ln -s Versions/Current/libmujoco.2.2.0.dylib /Applications/MuJoCo.app/Contents/Frameworks/mu
joco.framework/mujoco

After this, build works correctly, so I would guess that this symlink is missing from the dmg.

saran-t commented 2 years ago

This is my bad: I forgot that Apple's notarization requirement is such that the MuJoCo.app bundle needs to be "sealed". This prevents us from having the symlink in the copy of mujoco.framework that lives inside MuJoCo.app in a way that would make it usable as a framework for building other applications. (In other words, we had to explicitly delete the crucial symlink when we submit MuJoCo.app for notarization, which is a requirement for macOS to allow the app to be run when downloaded over the Internet)

The copy of mujoco.framework that's shipped in the same DMG but separate from MuJoCo.app should have the necessary symlink. I guess we need to update the instructions to ask people to copy mujoco.framework somewhere and point the Makefile to it.

saran-t commented 2 years ago

I'm mistaken yet again. Turns out the failure to sign and notarize was my fault, not Apple's restriction. I believe I have now successfully restructured the bundles in such a way as to allow it to be signed, notarized, and have the embedded framework be usable. Stay tuned.

saran-t commented 1 year ago

This is now fully resolved in the 2.2.1 release.

adzcai commented 1 year ago

Hmm, I still had to add the same symlink to get this to work. Not sure if this is maybe an issue with my setup? I'm just running clang++ from the command line using the MacOS Makefile:

$ clang++ -O2 -F/Applications/MuJoCo.app/Contents/Frameworks -I/usr/local/include -pthread -std=c++17 -stdlib=libc++ -L/usr/local/lib -Wl,-rpath,/Applications/MuJoCo.app/Contents/Frameworks    basic.cc      -framework mujoco -lglfw -o basic

> ld: framework not found mujoco
> clang: error: linker command failed with exit code 1 (use -v to see invocation)
> make: *** [all] Error 1

$ cd /Applications/MuJoCo.app/Contents/Frameworks/mujoco.framework
$ ls -l

> total 0
> lrwxr-xr-x  1 alexandercai  admin   24 Jun 20 13:41 Headers -> Versions/Current/Headers
> lrwxr-xr-x  1 alexandercai  admin   24 Jun 20 13:41 Modules -> Versions/Current/Modules
> lrwxr-xr-x  1 alexandercai  admin   26 Jun 20 13:41 Resources -> Versions/Current/Resources
> drwxr-xr-x@ 4 alexandercai  admin  128 Jun 20 13:21 Versions

$ ln -s Versions/Current/libmujoco.2.3.6.dylib mujoco
$ cd -
$ clang++ -O2 -F/Applications/MuJoCo.app/Contents/Frameworks -I/usr/local/include -pthread -std=c++17 -stdlib=libc++ -L/usr/local/lib -Wl,-rpath,/Applications/MuJoCo.app/Contents/Frameworks    basic.cc      -framework mujoco -lglfw -o basic

Everything works fine after that. Just thought I'd leave this here.

nik7273 commented 4 months ago

+1, I had the same error as @adzcai and I had to add the missing symlink to get this to compile, using that same MacOS Makefile. All I did was download the .dmg and drag MuJoCo.app to the Applications/ directory beforehand.

@saran-t is it maybe worth taking another look at whether the bundle should be fixed? or is this an issue with our setups somehow?

kevinzakka commented 1 month ago

@saran-t Can confirm this is still an issue in 3.1.6.

saran-t commented 1 month ago

Can we just remove the Makefile altogether?

LandonPattison commented 2 weeks ago

For anyone having issues with symlink on MacOS, when adding symlink make sure that libmujoco.x.x.x is the version of Mujoco you are using

ln -s Versions/Current/libmujoco.x.x.x.dylib /Applications/MuJoCo.app/Contents/Frameworks/mu

yuvaltassa commented 2 weeks ago

Can we just remove the Makefile altogether?

@saran-t I agree we should remove the makefiles, but this issue is unrelated right? This is about our macOS packaging script, no?