You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given the simple program below libclang is not able to find cmath while making the translation unitj
// test.cpp
#include<cmath>intmain() {
return1;
}
The script below and a fresh virtual environment gives an error when attempting to parse the translation unit. It cannot find the location of libclang.dylib.
Traceback (most recent call last):
File "[...]/venv/lib/python3.13/site-packages/clang/cindex.py", line 3949, in get_cindex_library
library = cdll.LoadLibrary(self.get_filename())
File "/opt/homebrew/Cellar/[email protected]/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ctypes/__init__.py", line 471, in LoadLibrary
return self._dlltype(name)
~~~~~~~~~~~~~^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ctypes/__init__.py", line 390, in __init__
self._handle = _dlopen(self._name, mode)
~~~~~~~^^^^^^^^^^^^^^^^^^
OSError: dlopen(libclang.dylib, 0x0006): tried: 'libclang.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibclang.dylib' (no such file), '/opt/homebrew/lib/libclang.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/libclang.dylib' (no such file), '/opt/homebrew/lib/libclang.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/libclang.dylib' (no such file), '/usr/lib/libclang.dylib' (no such file, not in dyld cache), 'libclang.dylib' (no such file)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<python-input-0>", line 7, in <module>
translation_unit = clang.cindex.TranslationUnit.from_source(filename, comp_args)
File "[...]/venv/lib/python3.13/site-packages/clang/cindex.py", line 2991, in from_source
index = Index.create()
File "[...]/venv/lib/python3.13/site-packages/clang/cindex.py", line 2877, in create
return Index(conf.lib.clang_createIndex(excludeDecls, 0))
^^^^^^^^
File "[...]/venv/lib/python3.13/site-packages/clang/cindex.py", line 224, in __get__
value = self.wrapped(instance)
File "[...]/venv/lib/python3.13/site-packages/clang/cindex.py", line 3922, in lib
lib = self.get_cindex_library()
File "[...]/venv/lib/python3.13/site-packages/clang/cindex.py", line 3956, in get_cindex_library
raise LibclangError(msg)
clang.cindex.LibclangError: dlopen(libclang.dylib, 0x0006): tried: 'libclang.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibclang.dylib' (no such file), '/opt/homebrew/lib/libclang.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/libclang.dylib' (no such file), '/opt/homebrew/lib/libclang.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/libclang.dylib' (no such file), '/usr/lib/libclang.dylib' (no such file, not in dyld cache), 'libclang.dylib' (no such file). To provide a path to libclang use Config.set_library_path() or Config.set_library_file().
Manually adding in the location of libclang.dylib allows the translation unit to compile, but gives diagnostic warnings that cmath could not be found
import clang.cindex
clang.cindex.Config.set_library_path("/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/")
filename = "./test.cpp"
comp_args = [
"-std=c++17",
] # Add any necessary compiler flags here
print("args: ", comp_args)
translation_unit = clang.cindex.TranslationUnit.from_source(filename, comp_args)
for diag in translation_unit.diagnostics:
print("Diagnostic:\n")
print(diag)
./test.cpp:1:10: fatal error: 'cmath' file not found
Then attempting to manually add the resource directory still does not allow libclang to find the correct cmath
import clang.cindex
clang.cindex.Config.set_library_path("/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/")
filename = "./test.cpp"
comp_args = [
"-std=c++17",
"-resource-dir", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/16"
] # Add any necessary compiler flags here
print("args: ", comp_args)
translation_unit = clang.cindex.TranslationUnit.from_source(filename, comp_args)
for diag in translation_unit.diagnostics:
print("Diagnostic:\n")
print(diag)
args: ['-std=c++17', '-resource-dir', '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/16']
Diagnostic:
./test.cpp:1:10: fatal error: 'cmath' file not found
System information
Software:
System Software Overview:
System Version: macOS 14.7 (23H124)
Kernel Version: Darwin 23.6.0
Boot Volume: Macintosh HD
Hardware:
Hardware Overview:
Model Name: MacBook Pro
Model Identifier: Mac14,5
Chip: Apple M2 Max
System Firmware Version: 11881.1.1
xcode-select -v
xcode-select version 2408.
clang++ --version
Apple clang version 16.0.0 (clang-1600.0.26.3)
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
pip freeze
clang==17.0.6
libclang==18.1.1
The text was updated successfully, but these errors were encountered:
Given the simple program below libclang is not able to find cmath while making the translation unitj
The script below and a fresh virtual environment gives an error when attempting to parse the translation unit. It cannot find the location of libclang.dylib.
Manually adding in the location of libclang.dylib allows the translation unit to compile, but gives diagnostic warnings that cmath could not be found
Then attempting to manually add the resource directory still does not allow libclang to find the correct cmath
System information
The text was updated successfully, but these errors were encountered: