0

Compiling .c files to a single LLVM IR and link multiple libraries during the compilation.

An example here with gcc:

gcc -c -Wall -g3 -DVERSION=\"1.1.2\" ssl_proxy.c -o ssl_proxy.o
gcc -o ssl_proxy ssl_proxy.o  -lssl -lcrypto

Now, I want to compile the ssl_proxy.c to ssl_proxy.ll, simply using llvm-gcc -S -emit-llvm won't work as it will not let me link -lssl -lcrypto libraries.

Through this example I hope people can explain a bit more details about compilation with llvm-gcc (not clang), so that all visitors can learn from it and know how to compile complex multiple sources into one LLVM IR.

cache
  • 1,239
  • 3
  • 13
  • 21

1 Answers1

1

Compiling source files into LLVM IR does not perform linking, so it does not require any libraries - it just needs the headers.

Oak
  • 26,231
  • 8
  • 93
  • 152
  • Then how should I perform the link with `-lssl -lcrypto` in this case for IR? – cache Aug 20 '14 at 19:15
  • @cache the best approach is to let clang do the linking - give it your IR file as one of the inputs. You can also link directly with the gold linker if you install [LLVM's plugin for it](http://llvm.org/docs/GoldPlugin.html), and that way you also enjoy some link-time optimization. – Oak Aug 20 '14 at 19:47
  • Thanks! But as I said if you could put more details and focusing on the example I provided. That may be the best way for ppl to learn. – cache Aug 20 '14 at 20:23
  • @ Oak So could you please give detail commands to make the above into the IR and properly link those flags? – cache Aug 20 '14 at 23:34