如何使用GCC编译GHCS生成C代码
我想从Haskell程序生成C代码,并使用GCC将生成的C代码汇编为汇编。因此,我在我的Haskell源文件上构建了自己的未注册版本的GHC版本,并用-C
调用它。这生成了.hc
文件,这只是常规的C代码。
现在,我想用GCC编译此C文件。因此,必须将包含路径设置为GHC,包括文件夹,因此GCC可以找到各种标题。这是我调用GCC的方式(我将生成的Hello..hc文件重命名为Hello.c):
gcc -I /usr/local/lib/ghc-9.5.20220505/rts/include/ hello.c
但是我会收到以下错误:
hello.C:7:5: error: uninitialized ‘const rFD_bytes’ [-fpermissive]
7 | IB_(rFD_bytes);
| ^~~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:264:37: note: in definition of macro ‘IB_’
264 | #define IB_(X) static const char X[]
| ^
hello.C:7:5: error: storage size of ‘rFD_bytes’ isn’t known
7 | IB_(rFD_bytes);
| ^~~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:264:37: note: in definition of macro ‘IB_’
264 | #define IB_(X) static const char X[]
| ^
hello.C:12:5: error: uninitialized ‘const rFB_bytes’ [-fpermissive]
12 | IB_(rFB_bytes);
| ^~~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:264:37: note: in definition of macro ‘IB_’
264 | #define IB_(X) static const char X[]
| ^
hello.C:12:5: error: storage size of ‘rFB_bytes’ isn’t known
12 | IB_(rFB_bytes);
| ^~~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:264:37: note: in definition of macro ‘IB_’
264 | #define IB_(X) static const char X[]
| ^
hello.C: In function ‘void* (* (* sIx_entry())())()’:
/usr/local/lib/ghc-9.5.20220505/rts/include/stg/Regs.h:522:49: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
522 | #define FunReg ((StgFunTable *)((void *)BaseReg - STG_FIELD_OFFSET(struct PartCapability_, r)))
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:328:39: note: in definition of macro ‘JMP_’
328 | #define JMP_(cont) return((StgFunPtr)(cont))
| ^~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/stg/Regs.h:525:36: note: in expansion of macro ‘FunReg’
525 | #define stg_gc_enter_1 (FunReg->stgGCEnter1)
| ^~~~~~
hello.C:39:6: note: in expansion of macro ‘stg_gc_enter_1’
39 | JMP_(stg_gc_enter_1);
| ^~~~~~~~~~~~~~
hello.C: At global scope:
hello.C:49:6: error: uninitialized ‘const sIx_info’ [-fpermissive]
49 | IRO_(sIx_info);
| ^~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:273:46: note: in definition of macro ‘IRO_’
273 | #define IRO_(X) static const StgWordArray (X)
| ^
hello.C:49:6: error: storage size of ‘sIx_info’ isn’t known
49 | IRO_(sIx_info);
| ^~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:273:46: note: in definition of macro ‘IRO_’
273 | #define IRO_(X) static const StgWordArray (X)
| ^
hello.C:55:5: error: storage size of ‘sIx_closure’ isn’t known
55 | IC_(sIx_closure);
| ^~~~~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:267:46: note: in definition of macro ‘IC_’
267 | #define IC_(X) static StgWordArray (X) GNU_ATTRIBUTE(aligned (8))
| ^
hello.C:64:6: error: storage size of ‘_uIR_srt’ isn’t known
64 | IRW_(_uIR_srt);
| ^~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:270:46: note: in definition of macro ‘IRW_’
270 | #define IRW_(X) static StgWordArray (X)
| ^
hello.C: In function ‘void* (* (* Main_main_entry())())()’:
/usr/local/lib/ghc-9.5.20220505/rts/include/stg/Regs.h:522:49: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
522 | #define FunReg ((StgFunTable *)((void *)BaseReg - STG_FIELD_OFFSET(struct PartCapability_, r)))
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:328:39: note: in definition of macro ‘JMP_’
328 | #define JMP_(cont) return((StgFunPtr)(cont))
| ^~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/stg/Regs.h:525:36: note: in expansion of macro ‘FunReg’
525 | #define stg_gc_enter_1 (FunReg->stgGCEnter1)
| ^~~~~~
hello.C:90:6: note: in expansion of macro ‘stg_gc_enter_1’
90 | JMP_(stg_gc_enter_1);
| ^~~~~~~~~~~~~~
hello.C: At global scope:
hello.C:115:6: error: storage size of ‘_uJ1_srt’ isn’t known
115 | IRW_(_uJ1_srt);
| ^~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:270:46: note: in definition of macro ‘IRW_’
270 | #define IRW_(X) static StgWordArray (X)
| ^
hello.C: In function ‘void* (* (* ZCMain_main_entry())())()’:
/usr/local/lib/ghc-9.5.20220505/rts/include/stg/Regs.h:522:49: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
522 | #define FunReg ((StgFunTable *)((void *)BaseReg - STG_FIELD_OFFSET(struct PartCapability_, r)))
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:328:39: note: in definition of macro ‘JMP_’
328 | #define JMP_(cont) return((StgFunPtr)(cont))
| ^~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/stg/Regs.h:525:36: note: in expansion of macro ‘FunReg’
525 | #define stg_gc_enter_1 (FunReg->stgGCEnter1)
| ^~~~~~
hello.C:141:6: note: in expansion of macro ‘stg_gc_enter_1’
141 | JMP_(stg_gc_enter_1);
| ^~~~~~~~~~~~~~
hello.C: At global scope:
hello.C:166:5: error: storage size of ‘rFC_closure’ isn’t known
166 | IC_(rFC_closure);
| ^~~~~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:267:46: note: in definition of macro ‘IC_’
267 | #define IC_(X) static StgWordArray (X) GNU_ATTRIBUTE(aligned (8))
| ^
hello.C:175:5: error: storage size of ‘rFE_closure’ isn’t known
175 | IC_(rFE_closure);
| ^~~~~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:267:46: note: in definition of macro ‘IC_’
267 | #define IC_(X) static StgWordArray (X) GNU_ATTRIBUTE(aligned (8))
有人知道吗,GHC在内部如何编译C代码,或者我必须如何在其中调用GCC?
I want to generate C code from a Haskell program and compile the generated C code down to assembly using GCC. Therefor I build my own unregistered version of GHC and invoked it with -C
on my Haskell source file. This generated a .hc
file, which is just regular C code.
Now I want to compile this C file with GCC. Therefor the include path has to be set to GHCs include folder, so GCC can find various headers. Here's how I invoked GCC (I renamed the generated hello.hc file to hello.c):
gcc -I /usr/local/lib/ghc-9.5.20220505/rts/include/ hello.c
But I get the following errors:
hello.C:7:5: error: uninitialized ‘const rFD_bytes’ [-fpermissive]
7 | IB_(rFD_bytes);
| ^~~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:264:37: note: in definition of macro ‘IB_’
264 | #define IB_(X) static const char X[]
| ^
hello.C:7:5: error: storage size of ‘rFD_bytes’ isn’t known
7 | IB_(rFD_bytes);
| ^~~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:264:37: note: in definition of macro ‘IB_’
264 | #define IB_(X) static const char X[]
| ^
hello.C:12:5: error: uninitialized ‘const rFB_bytes’ [-fpermissive]
12 | IB_(rFB_bytes);
| ^~~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:264:37: note: in definition of macro ‘IB_’
264 | #define IB_(X) static const char X[]
| ^
hello.C:12:5: error: storage size of ‘rFB_bytes’ isn’t known
12 | IB_(rFB_bytes);
| ^~~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:264:37: note: in definition of macro ‘IB_’
264 | #define IB_(X) static const char X[]
| ^
hello.C: In function ‘void* (* (* sIx_entry())())()’:
/usr/local/lib/ghc-9.5.20220505/rts/include/stg/Regs.h:522:49: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
522 | #define FunReg ((StgFunTable *)((void *)BaseReg - STG_FIELD_OFFSET(struct PartCapability_, r)))
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:328:39: note: in definition of macro ‘JMP_’
328 | #define JMP_(cont) return((StgFunPtr)(cont))
| ^~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/stg/Regs.h:525:36: note: in expansion of macro ‘FunReg’
525 | #define stg_gc_enter_1 (FunReg->stgGCEnter1)
| ^~~~~~
hello.C:39:6: note: in expansion of macro ‘stg_gc_enter_1’
39 | JMP_(stg_gc_enter_1);
| ^~~~~~~~~~~~~~
hello.C: At global scope:
hello.C:49:6: error: uninitialized ‘const sIx_info’ [-fpermissive]
49 | IRO_(sIx_info);
| ^~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:273:46: note: in definition of macro ‘IRO_’
273 | #define IRO_(X) static const StgWordArray (X)
| ^
hello.C:49:6: error: storage size of ‘sIx_info’ isn’t known
49 | IRO_(sIx_info);
| ^~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:273:46: note: in definition of macro ‘IRO_’
273 | #define IRO_(X) static const StgWordArray (X)
| ^
hello.C:55:5: error: storage size of ‘sIx_closure’ isn’t known
55 | IC_(sIx_closure);
| ^~~~~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:267:46: note: in definition of macro ‘IC_’
267 | #define IC_(X) static StgWordArray (X) GNU_ATTRIBUTE(aligned (8))
| ^
hello.C:64:6: error: storage size of ‘_uIR_srt’ isn’t known
64 | IRW_(_uIR_srt);
| ^~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:270:46: note: in definition of macro ‘IRW_’
270 | #define IRW_(X) static StgWordArray (X)
| ^
hello.C: In function ‘void* (* (* Main_main_entry())())()’:
/usr/local/lib/ghc-9.5.20220505/rts/include/stg/Regs.h:522:49: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
522 | #define FunReg ((StgFunTable *)((void *)BaseReg - STG_FIELD_OFFSET(struct PartCapability_, r)))
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:328:39: note: in definition of macro ‘JMP_’
328 | #define JMP_(cont) return((StgFunPtr)(cont))
| ^~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/stg/Regs.h:525:36: note: in expansion of macro ‘FunReg’
525 | #define stg_gc_enter_1 (FunReg->stgGCEnter1)
| ^~~~~~
hello.C:90:6: note: in expansion of macro ‘stg_gc_enter_1’
90 | JMP_(stg_gc_enter_1);
| ^~~~~~~~~~~~~~
hello.C: At global scope:
hello.C:115:6: error: storage size of ‘_uJ1_srt’ isn’t known
115 | IRW_(_uJ1_srt);
| ^~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:270:46: note: in definition of macro ‘IRW_’
270 | #define IRW_(X) static StgWordArray (X)
| ^
hello.C: In function ‘void* (* (* ZCMain_main_entry())())()’:
/usr/local/lib/ghc-9.5.20220505/rts/include/stg/Regs.h:522:49: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
522 | #define FunReg ((StgFunTable *)((void *)BaseReg - STG_FIELD_OFFSET(struct PartCapability_, r)))
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:328:39: note: in definition of macro ‘JMP_’
328 | #define JMP_(cont) return((StgFunPtr)(cont))
| ^~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/stg/Regs.h:525:36: note: in expansion of macro ‘FunReg’
525 | #define stg_gc_enter_1 (FunReg->stgGCEnter1)
| ^~~~~~
hello.C:141:6: note: in expansion of macro ‘stg_gc_enter_1’
141 | JMP_(stg_gc_enter_1);
| ^~~~~~~~~~~~~~
hello.C: At global scope:
hello.C:166:5: error: storage size of ‘rFC_closure’ isn’t known
166 | IC_(rFC_closure);
| ^~~~~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:267:46: note: in definition of macro ‘IC_’
267 | #define IC_(X) static StgWordArray (X) GNU_ATTRIBUTE(aligned (8))
| ^
hello.C:175:5: error: storage size of ‘rFE_closure’ isn’t known
175 | IC_(rFE_closure);
| ^~~~~~~~~~~
/usr/local/lib/ghc-9.5.20220505/rts/include/Stg.h:267:46: note: in definition of macro ‘IC_’
267 | #define IC_(X) static StgWordArray (X) GNU_ATTRIBUTE(aligned (8))
Does anyone know, how GHC internally compiles C code, or how I have to call GCC on it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论