1

I am trying to run a LLVM pass and have the following version of gcc:

Configured with:

-- prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.5.0
Thread model: posix

I downloaded the LLVM 3.2 source from the official site and have that unzipped in my project folder.

From the project folder I am trying to run the following command:

opt -load /Users/jigs/Downloads/CS_298/llvm-3.1.src/lib/Transforms/LLVMHello.dylib -hello -S morph_1.s mul -o=morph_output.s

I get an error saying opt does not exist. I am pretty sure opt is a part of LLVM source but it does not work.

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
Austin
  • 135
  • 4
  • 17
  • Maybe try using `./opt -load ...` – l'L'l Sep 07 '15 at 21:00
  • Hi, is still gives the same error : -bash: ./opt: No such file or directory – Austin Sep 07 '15 at 21:03
  • Is the `opt` command in the project directory? You need to call it from wherever it's at. Try doing `ls | grep opt` to check if it's there. – l'L'l Sep 07 '15 at 21:04
  • Hi, the opt command is in the llvm-3.1.src/tools folder. Still not able to run it. – Austin Sep 07 '15 at 21:09
  • What do you mean by *"the official site"*? The best, current, and only way to install Apple compiler and development suite, AFAIK, is to go to the `App Store` and download `Xcode` and then do `xcode-select --install` – Mark Setchell Sep 07 '15 at 21:14
  • @MarkSetchell: OP is trying to use the `opt` command, which isn't part of the standard Apple tools. – l'L'l Sep 07 '15 at 21:17
  • @ l'L'l , even if i run the command from the tools path, it does not find the opt and gives the error. @Mark We can also get the command line tools directly without downloading the Xcode. – Austin Sep 07 '15 at 21:22
  • @Austin: Are you including the `./` (period and forward slash) in front of the cmd? Try going into the directory with the opt tool and do `./opt` all by itself — see if that does anything. – l'L'l Sep 07 '15 at 21:31
  • @I'L'I it still gives me the same error even after including the ./ in front of cmd. – Austin Sep 08 '15 at 21:49

1 Answers1

2

The opt tool should appear in the bin directory after building (yours will be version 3.x.x), so I believe you are looking in the wrong place altogether. The opt in tools is a directory, so that's certainly not going to do much for you.

/llvm-3.7.0.src/build/bin

$ ./opt -version

LLVM (http://llvm.org/):
  LLVM version 3.7.0
  DEBUG build with assertions.
  Built Sep  8 2015 (17:54:06).
  Default target: x86_64-apple-darwin14.5.0
  Host CPU: ivybridge

If you don't have a bin directory present after compiling/building from source then something likely isn't correct within your makefile perhaps.

TIP: Often you can tell where the executables are that were built by looking at the most recently modified directory within the source tree. Also, I think the easiest and most hassle free way to build LLVM from source is to use CMake — it conveniently includes a CMakeLists.txt config.

l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • Hi I'L'I, it worked for me, I checked in the Debug+Asserts/bin/opt path and it the opt version command works from there. But somehow when i run the following command: ./opt -load /Users/jigs/Downloads/CS_298/llvm/Debug+Asserts/lib/LLVMHello.dylib -hello -S morph_1.s mul -o=morph_output.s i get the error as : opt: Too many positional arguments specified! Can specify at most 1 positional arguments: See: ./opt -help – Austin Sep 21 '15 at 03:34
  • @Austin: Glad you finally found the command. The error is unrelated to this question, so post another question regarding that. Please mark this answer correct if it helped you, cheers! – l'L'l Sep 21 '15 at 15:21