Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to link with clang and LLVM IR source code #61

Open
dequeb opened this issue Mar 21, 2024 · 1 comment
Open

unable to link with clang and LLVM IR source code #61

dequeb opened this issue Mar 21, 2024 · 1 comment

Comments

@dequeb
Copy link

dequeb commented Mar 21, 2024

Hi,

I'm novice on C. First of all, sorry if the question might look basic, but I'm confused with an error message trying to link LLVM IR code with gc.

Here is the context:

  1. I'm generating LLVM IR from uBasic source code (see my uBasic project for more context)
  2. l've make gc which gave me log.o in gc/build/src directory (I though I would have a gc.o...)
  3. l made compile.o from compile.ll using llc -filetype=obj compile.ll
  4. l tried to link compile.o and log.o to build my executable: clang compile.o gc/build/src/log.o -o compile
  5. this gave me the following errors:
Undefined symbols for architecture arm64:
  "_gc", referenced from:
      _main in compile.o
      _main in compile.o
      _.main in compile.o
  "_gc_malloc", referenced from:
      _.main in compile.o
      _.main in compile.o
      _.main in compile.o
      _.main in compile.o
      _.main in compile.o
      _.main in compile.o
      _.main in compile.o
      ...
  "_gc_start", referenced from:
      _main in compile.o
  "_gc_stop", referenced from:
      _main in compile.o
  "_llvm_gcda_emit_arcs", referenced from:
      ___llvm_gcov_writeout in log.o
  "_llvm_gcda_emit_function", referenced from:
      ___llvm_gcov_writeout in log.o
  "_llvm_gcda_end_file", referenced from:
      ___llvm_gcov_writeout in log.o
  "_llvm_gcda_start_file", referenced from:
      ___llvm_gcov_writeout in log.o
  "_llvm_gcda_summary_info", referenced from:
      ___llvm_gcov_writeout in log.o
  "_llvm_gcov_init", referenced from:
      ___llvm_gcov_init in log.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm a missing a gc.o file or is there something else I'm missing?

@dequeb
Copy link
Author

dequeb commented Mar 21, 2024

Hi,

Using what I knew, I found a solution, let me know what you think.

  1. I generated llvm from c using: clang -S -Wall -Wextra -pedantic -I../include *.c -emit-llvm
  2. I compiled gc.c and log.c to llvm using llc -filetype=obj gc.ll and llc -filetype=obj log.ll
  3. I linked everything together using : clang gc.o compile.o log.o -o compile

It worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant