haskell / haskell/cabal

GHCi invoked to compile Template Haskell files can't find symbols defined in C code

Open
#1,738 2 comments 0 reactions 0 assignees View on GitHub
old-milestone: ⊥ type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

I have a single symbol defined in a .c file, which I have listed in c-sources. I additionally have some Template Haskell code which expands to a call that ultimately uses that symbol (though it's not used at splice-expansion time). When I attempt to compile a file calling my TH (using Cabal, of course), I get:

```
Building direct-opengl-raw-1.5.0.0...
Preprocessing library direct-opengl-raw-1.5.0.0...
[ 6 of 226] Compiling Graphics.Rendering.OpenGL.Raw.EXT.SceneMarker ( src/Graphics/Rendering/OpenGL/Raw/EXT/SceneMarker.hs, dist/build/Graphics/Rendering/OpenGL/Raw/EXT/SceneMarker.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package array-0.4.0.1 ... linking ... done.
Loading package deepseq-1.3.0.1 ... linking ... done.
Loading package containers-0.5.0.0 ... linking ... done.
Loading package pretty-1.1.1.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
ghc:
lookupSymbol failed in relocateSection (relocate external)
dist/build/Graphics/Rendering/OpenGL/Raw/GetProcAddress.o: unknown symbol `_hs_OpenGLRaw_getProcAddress'
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Cabal build for the Template Haskell file and inspect how GHCi handles the listed c-sources. Trace the failure around dist/build/Graphics/Rendering/OpenGL/Raw/GetProcAddress.o and the missing _hs_OpenGLRaw_getProcAddress symbol; done means the reported build completes and the C-defined symbol is available during relocation.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, haskell
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.