C言語APIを使ってllvmに入れ子関数を実装しようとしています。私は意味チェックを実行した後(コンパイルしようとしているプログラムが正しいネスト参照を持つことを保証するために)、私はllvm内の同じスコープ内のすべての関数を定義し、すべての変数をグローバルとして設定します。私はこれが動作するように期待していたが、私は、コマンドでの.oファイルから実行ファイルを取得しながら、自分自身が大きな問題を持つが見つかりました:私は取得グローバル変数のいずれかllvm::GlobalValue::WeakAnyLinkage
またはllvm::GlobalValue::ExternalLinkage
リンケージを使用することによりClang-3.8グローバル変数を持つllvmバイトコードからオブジェクトファイルをコンパイルするときの `main 'への未定義参照
"llvm-as-3.8 output.ll| llc-3.8 -filetype=obj | clang-3.8 ../library/library.a -v -o out"
:
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12
...
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
; Function Attrs: nounwind uwtable define void @main() #0 {
、
もちろんグローバル変数を使用していないときに同じコマンドが問題にならなかったのは、allocaをglobalに変更しようとした理由で、変数が子関数で使用された場合です。
この問題の解決方法をお探しください。 ありがとうございます。 注1:私が使用LLVM-3.8
UPDATE:私は結果だった打ち鳴らすコマンドから-v削除 :このすべての変数はLLVM IRにおける私のプログラムの開始時に定義されていました
refined_output.o: In function
bsort': refined_output.ll:(.text+0x4): undefined reference to
x' refined_output.ll:(.text+0xa): undefined reference ton' refined_output.ll:(.text+0x10): undefined reference to
changed' refined_output.ll:(.text+0x22): undefined reference toi' refined_output.ll:(.text+0x2c): undefined reference to
changed' refined_output.ll:(.text+0x42): undefined reference toi' refined_output.ll:(.text+0x48): undefined reference to
n' refined_output.ll:(.text+0x50): undefined reference toi' refined_output.ll:(.text+0x59): undefined reference to
x' refined_output.ll:(.text+0x60): undefined reference toi' refined_output.ll:(.text+0x75): undefined reference to
x' refined_output.ll:(.text+0x7c): undefined reference toi' refined_output.ll:(.text+0x95): undefined reference to
changed' refined_output.ll:(.text+0xa3): undefined reference tochanged' refined_output.o: In function
swap': refined_output.ll:(.text+0xc3): undefined reference tox.1' refined_output.ll:(.text+0xca): undefined reference to
y' refined_output.ll:(.text+0xd1): undefined reference tox.1' refined_output.ll:(.text+0xd9): undefined reference to
t' refined_output.ll:(.text+0xe0): undefined reference tox.1' refined_output.ll:(.text+0xe7): undefined reference to
y' refined_output.ll:(.text+0xf2): undefined reference toy' refined_output.ll:(.text+0xf8): undefined reference to
t' refined_output.o: In functionmain': refined_output.ll:(.text+0x102): undefined reference to
i.4' refined_output.ll:(.text+0x10c): undefined reference toseed' refined_output.ll:(.text+0x123): undefined reference to
x.2' refined_output.ll:(.text+0x12a): undefined reference toi.4' refined_output.ll:(.text+0x130): undefined reference to
seed' refined_output.ll:(.text+0x15d): undefined reference toseed' refined_output.ll:(.text+0x166): undefined reference to
i.4' refined_output.ll:(.text+0x16c): undefined reference toi.4' refined_output.ll:(.text+0x177): undefined reference to
x.2' refined_output.ll:(.text+0x18d): undefined reference tox.2' refined_output.ll:(.text+0x19e): undefined reference to
x.2' refined_output.o: In functionprintArray': refined_output.ll:(.text+0x1c4): undefined reference to
msg' refined_output.ll:(.text+0x1cb): undefined reference tox.2' refined_output.ll:(.text+0x1d1): undefined reference to
n.3' refined_output.ll:(.text+0x1d8): undefined reference tomsg' refined_output.ll:(.text+0x1e3): undefined reference to
i.4' refined_output.ll:(.text+0x1f3): undefined reference tox.2' refined_output.ll:(.text+0x1fa): undefined reference to
i.4' refined_output.ll:(.text+0x208): undefined reference toi.4' refined_output.ll:(.text+0x20e): undefined reference to
i.4' refined_output.ll:(.text+0x214): undefined reference ton.3' refined_output.ll:(.text+0x21c): undefined reference to
i.4'clang: error: linker command failed with exit code 1 (use -v to see invocation)
次のように入力してください:
@x = external global i32*
@n = external global i32
@i = external global i32
@changed = external global i1
@x.1 = external global i32*
@y = external global i32*
@t = external global i32
@msg = external global i8*
@x.2 = external global i32*
@n.3 = external global i32
@i.4 = external global i32
@const_string_temp = private constant [3 x i8] c", \00", align 1
@const_string_temp.5 = private constant [2 x i8] c"\0A\00", align 1
@i.6 = external global i32
@x.7 = external global i32
@seed = external global i32
@const_string_temp.8 = private constant [16 x i8] c"Initial array: \00", align 1
@const_string_temp.9 = private constant [15 x i8] c"Sorted array: \00", align 1
これは私の手助けとなります。
私はそれを楽しみにしています。..
void main?本気ですか? – kfsone
int main()に変更しても何も変わりません。 –