ld64.lld undefined symbol for some OpenGL.framework functions
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Given the following C code (just meant as a repro, will not do anything):
```c
#include
int main(void) {
return (int)CGLSetCurrentContext((void*)0);
}
```
It will build successfully with: `clang lld-cgl-repro.c -framework OpenGL`
But when `-fuse-ld=lld` is added, it's apparently not able to find that symbol:
```cs
> clang lld-cgl-repro.c -framework OpenGL -fuse-ld=lld
ld64.lld: error: undefined symbol: CGLSetCurrentContext
>>> referenced by /var/folders/px/y6wj4c3x0tb891bpxtsf74_40000gn/T/lld-cgl-repro-fdb471.o:(symbol main+0x14)
```
However, I am able to link properly if I include `libGL.tbd`, which is listed in `reexported-libraries` in OpenGL.tbd.
```cs
> clang lld-cgl-repro.c -framework OpenGL -fuse-ld=lld /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.tbd
> llvm-nm a.out
U _CGLSetCurrentContext
0000000100000000 T __mh_execute_header
00000001000004c0 T _main
U dyld_stub_binder
> grep -n3 libGL /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/OpenGL.tbd
4-install-name: '/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL'
5-reexported-libraries:
6- - targets: [ x86_64-macos, x86_64-maccatalyst, arm64e-macos, arm64e-maccatalyst ]
7: libraries: [ '/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib',
8: '/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib' ]
```
Tested on macOS 26.5, `Homebrew clang version 22.1.8` + `Homebrew LLD 22.1.8`, Xcode 26.4.1.
Contributor guide
Research direction
Start with the lld-cgl-repro.c reproduction and compare the two clang link commands, then inspect OpenGL.tbd and its reexported libGL.tbd entry in the macOS SDK. Verify the behavior with and without explicitly passing libGL.tbd; done means -framework OpenGL alone resolves CGLSetCurrentContext under ld64.lld.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, macos
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100