Installed LLVM on OS X with brew but no path were set to the executable - classpath

I installed LLVM on OS X with brew by brew install llvm and I tested it with hello.c with llvm-gcc, and it generates the IR for me. However, when I want to execute the IR code with lli hello.ll or compile it to assembler by llc hello.ll, clang hello.s -x assembler -o hello and run it with ./hello. I got -bash: lli: command not found error. So I tried to add the class path as: export CLASSPATH="/usr/local/Cellar/llvm/3.6.2/bin/lli:$CLASSPATH". However, I still didn't add the class path successfully. Anyone has ideas?

As discussed in the comment, the actual path where executables located is in opt. So export PATH="/usr/local/opt/llvm/bin:$PATH" should set the environment variables for llvm.

Related

gcc not found when building buildroot

I'm trying to build an OS Image for Raspberry pi on MacOS.
make failed because gcc is missing so I installed it with homebrew.
Still I cannot build the image due to the same error:
% make raspberrypi0w_defconfig
...
% make menuconfig
...
% brew install gcc
...
% brew list --versions gcc
gcc 11.3.0_2
% gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include- dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
% make
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
You must install 'gcc' on your build machine
make: *** [dependencies] Error 1
Tried a make clean but I'm still getting the same error...
I ended up switching to gcc (it was a path issue).
clang is apple's C compiler, and when you type gcc, this is the compiler that is used by default. When you install gnu c, (using homebrew in my case), you still need to put it ahead of clang in the path.
However, using BuildRoot on MacOS ended up being a rabbit hole.
There are instructions here: https://github.com/generia/buildroot-osx
, but for me it was far simpler to setup an ubuntu VM and build on it. Which I did.

C++ wxWidgets: cross compilation from Raspberry Pi 3

I have a C++ application that uses WxWidgets. It compiles perfectly with g++ on my computer.
However I need to run the application on a Raspberry Pi 3. Compiling directly on Raspi takes almost an hour.
So I want to do a cross compilation: compile it on my computer and copy the executable to raspberry.
I tried to follow a tutorial, however the generated file is an "x86-64" file:
http://yasriady.blogspot.com/2015/10/how-to-build-wxwidgets-for-raspberry-pi.html
My computer:
Ubuntu 20.04.2 LTS;
g++ 9.3.0;
wxWidgets v3.1.5.0;
build flags for my computer: CC_FLAGS=-std=c++17 -w -c -rdynamic -W wx-config --cxxflags --libs --gl-libs geos-config --cflags -lgeos -lglut -lGLU -lGL -lm -lGLEW .
Should I re-install wxWidgets for arm? I'm new to cross-compilation
Thank you so much
I already have wxWidgets installed and compiling for x86. Afterwards, I installed wxWidgets for arm-linux following the tutorial.
When I run "make for the examples from the samples folder, the generated file is for x86.
Maybe "make" is compiling using the x86 compiler, not the newly installed arm compiler.
You should be able to cross-compile for RPi without any problems, double check that you've specified the correct --host option and didn't get any errors from configure (if you did, look at config.log to see why).

Compile Swift on Mac and run on Windows

How can I compile a swift file on Mac as an executable to run on Windows?
All I need is an executable that can be called from C# code.
If you have a proper swift library module for Windows, your swift compiler for macOS can generate object files for Windows, such as Hello.obj.
Moreover, you can build the executable (ex. Hello.exe) if you have the special linker and some C/C++ runtime object files for Windows.
All you need one is follows.
Copy the directories to the macOS from the package for Windows.
1) Install Swift for Windows ver-1.5 (https://swiftforwindows.codeplex.com) on Windows
2) Copy directories to macOS from Windows
SwiftForWindows/Swift/lib/swift // Swift library for Windows (MinGW)
SwiftForWindows/Swift/lib/mingw // C/C++ runtime object files (MinGW)
Install Swift compiler for MacOS (https://swift.org/builds/swift-3.0-release/xcode/swift-3.0-RELEASE/swift-3.0-RELEASE-osx.pkg)
You should use the same version for the library module and compiler. Use the version 3.0. Swift 3.0.1 or 3.1 will not work with SwiftForWindows-1.5.
Install MinGW linker with Mac Port
1) Install Mac Port (https:// www.macports.org/install.php)
2) $ sudo port install x86_64-w64-mingw32-binutils
3) Create directory bfd_ld and copy /opt/local/bin/x86_64-w64-mingw32-ld and name to ld
$ mkdir bfd_ld
$ cp -p /opt/local/bin/x86_64-w64-mingw32-ld bfd_ld/ld
More Settings
1) Rename the directory in macOS
mv SwiftForWindows/Swift/lib/swift/mingw SwiftForWindows/Swift/lib/swift/windows
2) Copy C runtime objects (3 files)
cp SwiftForWindows/Swift/lib/mingw/*.o bfd_ld
Compiling
echo "print(Hello)" > Hello.swift
~/Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain/usr/bin/swiftc -target x86_64-pc-windows-gnu -resource-dir SwiftForWindows/Swift/lib/swift -tools-directory bfd_ld -L SwiftForWindows/Swift/lib/mingw -lswiftSwiftOnoneSupport -o Hello.exe Hello.swift
This will generate Hello.exe. You can ignore the 'Warning: .drectve' message.
Running
The executable file will need the DLL's in the directory 'SwiftForWindows/My Programs'.
Copy Hello.exe to the directory in Windows and run it.
Good luck to you. Thanks.
If you want to run Swift code on Windows, the closest you can get is swift-windows. I have never used it but it looks like you can compile Swift 3.0 code to a Windows executable.
To download pre-built binaries, try this link. It requires Windows 10 64 bit and the Visual Studio 2015 SDK. Additionally you will have to have a cygwin or mingw environment.

How to force MATLAB 2016a to use gcc-4.7.x instead of the one I have (gcc-5.4.1)?

There are some posts about this for the older releases of MATLAB, but they don't seem to work for R2016a.
I'm trying to install MatConvNet on Ubuntu 16.04. When I run the vl_compilenn command as described here, it gives me a warning as follows:
Building with 'gcc'.
Warning: You are using gcc version '5.4.1'. The version of gcc is not supported.
The version currently supported with MEX is '4.7.x'. For a list of currently supported
compilers see: http://www.mathworks.com/support/compilers/current_release.
I have already installed gcc-4.7 and g++-4.7 using apt-get install gcc-4.7 g++-4.7. How can I force MATLAB to use these versions and not the default ones?
Few hints, not a complete tutorial how to do it.
Probably the simplest would be to edit the MATLAB's Mex XML configuration file:
mex -setup C
cc = mex.getCompilerConfigurations('C', 'Selected')
edit(cc.MexOpt)
The mex setup usually creates a copy in your home folder (~/.matlab/<version>/mex_C_glnca64.xml), so you should be able to edit it without root.
There you probably need to change the section:
<GCC>
<cmdReturns name="which gcc" />
</GCC>
which I guess searches for the location of the gcc command to your gcc version and assigns it to the $GCC variable. Plus you can change the version name in the header.
Additionally you need to do the same for the C++ language.
This works with R2016b:
Install the required GCC version with apt install (gcc-4.9 and g++-4.9 in my case).
Create a bin folder in your home, i.e. ~/bin.
Create the following links with ln:
ln -s /usr/bin/gcc-4.9 ~/bin/gcc
ln -s /usr/bin/g++-4.9 ~/bin/g++
If using CUDA, create a file called nvcc in the ~/bin folder, with the following contents (don't forget to make it executable: chmod +x ~/bin/nvcc):
Contents:
#!/bin/sh
exec /usr/lib/nvidia-cuda-toolkit/bin/nvcc -ccbin gcc-4.9 "$#"
If necessary replace /usr/lib/nvidia-cuda-toolkit/bin/nvcc with the correct location of the nvcc binary.
Open MATLAB and follow the instructions for compiling MatConvNet.

Installing GFortran on Mavericks

I have succeeded with installing numpy and now I am trying to install scipy on Mavericks. The requirement is GFortran but when I am trying to install it, I get a message:
"Unapproved caller.
SecurityAgent may only be invoked by Apple software."
Does anyone know how I can fix this issue?
Restarting the computer has fixed the issue.
I was able to get around this by using the installer command instead of the gui
## SETUP
# get pacakge
wget http://coudert.name/software/gfortran-4.9.0-Mavericks.dmg
# mount
hdiutil attach gfortran-4.9.0-Mavericks.dmg
# issue with clicking desktop icon then pkg icon
# "Unapproved caller. SecurityAgent may only be invoked by Apple software"
## INSTALL
sudo installer -pkg /Volumes/gfortran-4.9.0-Mavericks/gfortran.pkg -target /
## test install
which gfortran
/usr/local/bin/gfortran
Another solution might be to use the brew/fink/macports package. I'm using this package instead of e.g. brew install gcc because (when R is compiling fortran code), I'm getting:
FATAL:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../libexec/as/x86_64/as: I don't understand 'm' flag!