import os
import sys
import ctypes
from pathlib import Path
import platform
from datetime import datetime
def find_library():
search_paths = [
Path.cwd(),
Path(__file__).parent.parent,
Path("/usr/lib"),
Path("/usr/local/lib"),
Path(__file__).parent.parent / "build" / "lib",
Path(__file__).parent.parent / "target" / "debug",
Path(__file__).parent.parent / "target" / "debug" / "deps",
Path(__file__).parent.parent / "target" / "release",
Path(__file__).parent.parent / "target" / "release" / "deps",
]
if platform.system() == "Windows":
lib_names = ["bitcoinpqc.dll"]
elif platform.system() == "Darwin": lib_names = ["libbitcoinpqc.dylib", "libbitcoinpqc.so"]
else: lib_names = ["libbitcoinpqc.so", "libbitcoinpqc.dylib"]
print("Searching for library...")
for path in search_paths:
print(f"Looking in {path}")
for name in lib_names:
lib_path = path / name
if lib_path.exists():
print(f"Found at: {lib_path}")
return str(lib_path)
print("Library not found in standard locations")
return None
def main():
print("Bitcoin PQC Library Check Utility")
print("=================================")
if Path(__file__).parent.name == "python":
print("Running from python source directory")
lib_path = find_library()
if lib_path is None:
print("Could not find the libbitcoinpqc library")
print("\nTry building the C library with:")
print(" mkdir -p build && cd build && cmake .. && make")
print(" cd ..")
sys.exit(1)
try:
print(f"Attempting to load {lib_path}")
lib = ctypes.CDLL(lib_path)
print("Successfully loaded the library!")
if hasattr(lib, "bitcoin_pqc_public_key_size"):
print("Found bitcoin_pqc_public_key_size function")
else:
print("WARNING: bitcoin_pqc_public_key_size function not found")
print("\nLibrary Information:")
print(f" Path: {lib_path}")
print(f" Size: {os.path.getsize(lib_path) / 1024:.1f} KB")
print(f" Modified: {datetime.fromtimestamp(os.path.getmtime(lib_path)).strftime('%Y-%m-%d %H:%M:%S')}")
print("\nAll checks passed. The Python bindings should work correctly.")
return 0
except Exception as e:
print(f"Failed to load the library: {e}")
print("\nPossible solutions:")
print("1. Make sure you have built the C library correctly")
print("2. Check that the library file exists and is readable")
print("3. On Linux, add the library directory to LD_LIBRARY_PATH:")
print(" export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/library/dir")
print("4. On macOS, add the library directory to DYLD_LIBRARY_PATH:")
print(" export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/path/to/library/dir")
sys.exit(1)
if __name__ == "__main__":
sys.exit(main())