Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osx compile error #32

Open
dandingol03 opened this issue Jul 26, 2021 · 3 comments
Open

osx compile error #32

dandingol03 opened this issue Jul 26, 2021 · 3 comments

Comments

@dandingol03
Copy link

dandingol03 commented Jul 26, 2021

os: mac big sur
i have installed the panda3D from the official pkg file. However there is an error when i run the ./3d-game-shaders-for-beginners:
dyld: Library not loaded: @loader_path/../lib/libp3framework.1.10.dylib

@dandingol03 dandingol03 changed the title dyld: Library not loaded: @loader_path/../lib/libp3framework.1.10.dylib mac compile error Jul 26, 2021
@dandingol03 dandingol03 changed the title mac compile error osx compile error Jul 26, 2021
@ghost
Copy link

ghost commented Aug 1, 2021

Hey @dandingol03 can you post more details of how you compiled your program (i.e., which commands you used)?

It seems like your binary has the incorrect library path encoded in it, so the loader can't find the panda dylib when you try to run.

Can you try to run the command below to list the libraries linked with your binary?

otool -L 3d-game-shaders-for-beginners

After that, you can use a tool called install_name_tool to fix the path yourself:

install_name_tool -change <path to libp3framework returned by otool> <correct path to libp3framework> 3d-game-shaders-for-beginners

@ghost
Copy link

ghost commented Aug 1, 2021

Here's what I've done.

Generate object file

$ clang++ \                       
  -c src/main.cxx \                
  -o 3d-game-shaders-for-beginners.o \
  -std=gnu++11 \                  
  -g \           
  -O2 \    
  -I/Library/Developer/Panda3D/include

Generate binary

$ clang++ \
  3d-game-shaders-for-beginners.o \
  -o 3d-game-shaders-for-beginners \  
  -L/Library/Developer/Panda3D/lib \
  -lp3framework \
  -lpanda \
  -lpandafx \                         
  -lpandaexpress \
  -lpandaphysics \  
  -lp3dtoolconfig \
  -lp3dtool \
  -lpthread

List dylibs linked to binary

$ otool -L 3d-game-shaders-for-beginners
3d-game-shaders-for-beginners:
	@loader_path/../lib/libp3framework.1.10.dylib (compatibility version 1.10.0, current version 1.10.9)
	@loader_path/../lib/libpanda.1.10.dylib (compatibility version 1.10.0, current version 1.10.9)
	@loader_path/../lib/libpandafx.1.10.dylib (compatibility version 1.10.0, current version 1.10.9)
	@loader_path/../lib/libpandaexpress.1.10.dylib (compatibility version 1.10.0, current version 1.10.9)
	@loader_path/../lib/libpandaphysics.1.10.dylib (compatibility version 1.10.0, current version 1.10.9)
	@loader_path/../lib/libp3dtoolconfig.1.10.dylib (compatibility version 1.10.0, current version 1.10.9)
	@loader_path/../lib/libp3dtool.1.10.dylib (compatibility version 1.10.0, current version 1.10.9)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.60.1)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 904.4.0)

As you can see in the output above, all panda-related libraries were marked as a directory above and in a lib dir, which doesn't exist.

We could either copy the dylibs to that directory or fix the paths. I chose to fix them.

Fix linked libraries paths

install_name_tool -change '@loader_path/../lib/libp3framework.1.10.dylib' /Library/Developer/Panda3D/lib/libp3framework.1.10.dylib 3d-game-shaders-for-beginners

install_name_tool -change '@loader_path/../lib/libpanda.1.10.dylib' /Library/Developer/Panda3D/lib/libpanda.1.10.dylib 3d-game-shaders-for-beginners

install_name_tool -change '@loader_path/../lib/libpandafx.1.10.dylib' /Library/Developer/Panda3D/lib/libpandafx.1.10.dylib 3d-game-shaders-for-beginners

install_name_tool -change '@loader_path/../lib/libpandaexpress.1.10.dylib' /Library/Developer/Panda3D/lib/libpandaexpress.1.10.dylib 3d-game-shaders-for-beginners

install_name_tool -change '@loader_path/../lib/libpandaphysics.1.10.dylib' /Library/Developer/Panda3D/lib/libpandaphysics.1.10.dylib 3d-game-shaders-for-beginners

install_name_tool -change '@loader_path/../lib/libp3toolconfig.1.10.dylib' /Library/Developer/Panda3D/lib/libp3toolconfig.1.10.dylib 3d-game-shaders-for-beginners

install_name_tool -change @loader_path/../lib/libp3dtoolconfig.1.10.dylib /Library/Developer/Panda3D/lib/libp3dtoolconfig.1.10.dylib 3d-game-shaders-for-beginners

install_name_tool -change @loader_path/../lib/libp3dtool.1.10.dylib /Library/Developer/Panda3D/lib/libp3dtool.1.10.dylib 3d-game-shaders-for-beginners

Result

$ otool -L 3d-game-shaders-for-beginners
3d-game-shaders-for-beginners:
	/Library/Developer/Panda3D/lib/libp3framework.1.10.dylib (compatibility version 1.10.0, current version 1.10.9)
	/Library/Developer/Panda3D/lib/libpanda.1.10.dylib (compatibility version 1.10.0, current version 1.10.9)
	/Library/Developer/Panda3D/lib/libpandafx.1.10.dylib (compatibility version 1.10.0, current version 1.10.9)
	/Library/Developer/Panda3D/lib/libpandaexpress.1.10.dylib (compatibility version 1.10.0, current version 1.10.9)
	/Library/Developer/Panda3D/lib/libpandaphysics.1.10.dylib (compatibility version 1.10.0, current version 1.10.9)
	/Library/Developer/Panda3D/lib/libp3dtoolconfig.1.10.dylib (compatibility version 1.10.0, current version 1.10.9)
	/Library/Developer/Panda3D/lib/libp3dtool.1.10.dylib (compatibility version 1.10.0, current version 1.10.9)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.60.1)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 904.4.0)

@ngn999
Copy link

ngn999 commented Feb 11, 2022

this is not a compile error, it is a runtime error.
one simple way is to add pand3d to the dyld search path, you can run like this:

DYLD_LIBRARY_PATH=/Library/Developer/Panda3D/lib ./3d-game-shaders-for-beginners

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants