尝试编译第8章的输出时LLVM教程3.6链接器错误

时间:2015-04-26 01:18:07

标签: c++ llvm llvm-clang llvm-c++-api

我正在研究llvm教程: http://llvm.org/releases/3.6.0/docs/tutorial/index.html

第8章的代码编译得很好并发出了IR但是我无法编译发出的IR。代码清单是复制和粘贴的,以减少我的代码中出现错字的可能性。我修改的唯一内容是build命令,因为llvm-config默认为旧版本。 构建命令:

clang++ -g -O3 toy.cpp `llvm-config-3.6 --cxxflags --ldflags --system-libs --libs core mcjit native` -o toy

运行它(我从原始命令中删除了&因为这似乎引发了错误):

./toy < programs/basic.ks | clang-3.6 -x ir -

输出如下:

; ModuleID = 'my cool jit'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"

declare double @printd(double)

define double @main() {
entry:
  %calltmp = call double @printd(double 4.200000e+01), !dbg !14
  ret double %calltmp, !dbg !14
}

!llvm.module.flags = !{!0, !1}
!llvm.dbg.cu = !{!2}

!0 = !{i32 2, !"Debug Info Version", i32 2}
!1 = !{i32 2, !"Dwarf Version", i32 2}
!2 = !{!"0x11\002\00Kaleidoscope Compiler\000\00\000\00\001", !3, !4, !4, !5, !4, !4} ; [ DW_TAG_compile_unit ] [./fib.ks] [DW_LANG_C]
!3 = !{!"fib.ks", !"."}
!4 = !{}
!5 = !{!6, !11}
!6 = !{!"0x2e\00printd\00printd\00\001\000\001\000\000\00256\000\001", !3, !7, !8, null, double (double)* @printd, null, null, !4} ; [ DW_TAG_subprogram ] [line 1] [def] [printd]
!7 = !{!"0x29", !3}                               ; [ DW_TAG_file_type ] [./fib.ks]
!8 = !{!"0x15\00\000\000\000\000\000\000", null, null, null, !9, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
!9 = !{!10, !10}
!10 = !{!"0x24\00double\000\0064\0064\000\000\004", null, null} ; [ DW_TAG_base_type ] [double] [line 0, size 64, align 64, offset 0, enc DW_ATE_float]
!11 = !{!"0x2e\00main\00main\00\002\000\001\000\000\00256\000\002", !3, !7, !12, null, double ()* @main, null, null, !4} ; [ DW_TAG_subprogram ] [line 2] [def] [main]
!12 = !{!"0x15\00\000\000\000\000\000\000", null, null, null, !13, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
!13 = !{!10}
!14 = !MDLocation(line: 2, column: 8, scope: !11)
warning: overriding the module target triple with x86_64-apple-macosx10.10.0
1 warning generated.
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

1 个答案:

答案 0 :(得分:0)

示例代码使用dump()方法打印出IR,打印到stderr。您应该在管道之前将stderr重定向到stdout,如下所示:

./toy < programs/basic.ks 2>&1 | clang-3.6 -x ir -
相关问题