How to compile a julia script? - compilation

I have noticed that the version 0.4.* of julia has a --compile option.
Strangely, I cannot find any documentation about it.
I was trying (in Ubuntu), to compile a julia script to an executable LLVM bytecode file. But until here, I failed:
julia --compile=yes --output-bc test.bc test.jl
Segmentation fault (core dumped)
I also can get this error message:
julia --compile=yes --output-bc test.bc test.jl
ERROR: could not open file boot.jl
This error does not appear anymore, if I put a boot.jl file in the same folder.
How should I do to compile a julia script to an executable/obfuscated bytecode ?
Edit: FYI, my test.jl file contains only print(123)

Here's an example, from a julia source build on OS X, with /tmp/test.jl as:
function foo()
print(123)
end
precompile(foo, ())
And julia/base/userimg.jl as include("/tmp/test.jl")
Execute the following inside the julia/base directory:
julia --compile=yes --output-bc test.bc -J ../usr/lib/julia/inference.ji sysimg.jl
Then run llvm-dis test.bc -o test.ll. Somewhere in the (enormous) image we have the relevant bytecode for the test function:
define internal %jl_value_t* #julia_foo_22542() {
top:
%0 = alloca [4 x %jl_value_t*], align 8, !dbg !51528
...
That said, as of now (Dec. 2015), Julia is not usable for ahead-of-time compilation of stand-alone executables. However, the following may be of interest:
https://github.com/dhoegh/BuildExecutable.jl (doesn't use --output-bc, as yet, but has a nicer user interface and that option would be easy to add)
https://github.com/JuliaLang/julia/pull/13677

Related

How do I compile the source code for ADB (Android Debug Bridge)?

I'm trying to run a memory error detector (like Valgrind's Memcheck or Drmemory) on the ADB software. However, I'm having trouble figuring it how to build/compile the source code. I'm using linux (ubuntu).
https://github.com/aosp-mirror/platform_system_core/tree/master/adb
Do I need a makefile? Or is there something wrong with my understanding on how to go about doing this? Maybe there's a way that I can use Memcheck/Dr. Memory on the actual program when it's run in Android Studio? I don't believe there are any instructions, or a makefile in the source code.
I've tried compiling the main.cpp file in the client folder with g++, but it says it doesn't have access to the sysdep.h file.
Compiled using:
$ cd client
$ g++ -std=c++11 main.cpp -o main
Error message:
fatal error: sysdep.h: No such file or directory
Take a look at this documentation for the AOSP ADB tool:
https://source.android.com/setup/build/adb#building_adb_build-adb
From my understanding you need to download the AOSP source code then run the following commands:
source ~/aosp/build/envsetup.sh
cd ~/aosp/system/core/adb
mm # <- That's not a typo
This command should take a while (especially on the first run) but you should get a compiled adb executable in the ~/aosp/out folder somewhere (I can't verify on this computer as it doesn't have enough ram to complete a build...)
Also to show the help menu, type:
hmm

Compiling GNU Guile 1.8.8 with msys2: Undefined reference to '_imp__scm_shell' and '_imp__scm_boot_guile'

I apologize if this is a duplicate, but I was unable to find a question similar to mine on this site.
I am trying to compile GNU Guile 1.8.8 with msys2 on Windows, but am running into undefined reference errors to '_imp__scm_shell' and '_imp__scm_boot_guile'. Here are the steps I have taken so far:
Install and update msys2-20170918
Install base-devel, mingw-w64-i686-toolchain, mingw-w64-x86_64-toolchain, mingw-w64-i686-libtool, and mingw-w64-x86_64-libtool with pacman
Download GNU Guile 1.8.8
Open msys2\mingw32.exe and cd to the source code's directory
Run ./configure --disable-error-on-warning
Run make
After a few minutes, it exits with the following errors:
guile-guile.o: In function 'inner_main':
C:\Users\<username>\Downloads\guile-1.8.8\libguile/guile.c:53: undefined reference to '_imp__scm_shell'
guile-guile.o: In function 'main':
C:\Users\<username>\Downloads\guile-1.8.8\libguile/guile.c:63: undefined refencere to '_imp__scm_boot_guile'
Here is the log file, in case it is useful: https://drive.google.com/open?id=1dUj8ThwZKYL1Haehq3LFu6QAzkbDqqYv
Information on what I'm doing wrong would be much appreciated.
It is perfectly possible to build guile 1.8 in this environment, with a few patches, and only for 32 bits. There is even a binary package available.

How to use Intel fortran compiler with MKL on command line

I've freshly installed the IntelĀ® Parallel Studio XE Composer Edition for Fortran OS X* (student version). It comes with the Math Kernel Library, which is why I bought it. I'm having a hard time getting started with MKL. Here's what I've done step-by-step.
1) Installed IntelĀ® Parallel Studio XE Composer Edition for Fortran OS X* (no problem). I can run a 'hello world' script using ifort and throw the -mkl link command on at the end with no problem (not calling any mkl commands just yet).
2) Following these instructions I set my environment variables using a script provided by intel (located in opt/intel/bin to be precise). I have the intel 64-bit architecture (according to ifort -V) so I use bash mklvars.sh intel64 mod ilp64. It runs without error (or any output).
3) I write the following code to use MKL's gemm command for fortran95. Just multiplying 2 matrices.
program test
implicit none
real, dimension(2,2) :: testA, testB, testC
testA = 1
testB = 1
testC = 0 ! I don't think I need this line, but it shouldn't matter
call gemm(testA, testB, testC)
write(*,*) testC
end program test
4) I compile with ifort test_mkl.f90 -o test -mkl. I get the following error:
Undefined symbols for architecture x86_64:
"_gemm_", referenced from:
_MAIN__ in ifortSTVOrB.o
ld: symbol(s) not found for architecture x86_64
5) I try ifort test_mkl.f90 -o test -L/opt/intel/mkl/lib -mkl and get the same result.
I notice a lot of people using MKL begin their code with USE mkl95_blas, ONLY: gemm, so I put that in above implicit none in both of the above examples and get:
test_mkl.f90(4): error #7002: Error in opening the compiled module file. Check INCLUDE paths. [MKL95_BLAS]
USE mkl95_blas, ONLY: gemm
--------^
test_mkl.f90(12): error #6406: Conflicting attributes or multiple declaration of name. [GEMM]
call gemm(testA, testB, testC )
---------^
test_mkl.f90(4): error #6580: Name in only-list does not exist. [GEMM]
USE mkl95_blas, ONLY: gemm
--------------------------^
compilation aborted for test_mkl.f90 (code 1)
Any ideas as to what the problem is or how to fix this? I have successfully run a simple script in XCODE using MKL, so it's definitely something I'm doing and not my installation.
The documentation tells you to use the "source" command on the provided compilervars.sh script to make all the resources available. For example:
source //bin/compilervars.sh
This will add MKL to the include and library paths so that the compiler and linker can find them. If you need more help, please ask in https://software.intel.com/en-us/forums/intel-fortran-compiler-for-linux-and-mac-os-x You can get MKL-specific help in https://software.intel.com/en-us/forums/intel-math-kernel-library
I think your program has some bugs, first, you have to include blas95 at the beginning of your code, then, you can't use gemm, you have to choose the specific version of gemm. For example, to do real number matrix multiplication, you have to use dgemm, here is my code(Which I called test.f90), which compiles successfully using ifort -mkl test.f90 -o test.exe
program test
use blas95
implicit none
real*8,dimension(2,2)::testA,testB,testC
integer::i,j
testA=1d0
testB=1d0
testC=1d0
call dgemm("N", "N", 2, 2, 2, 1d0, A, 2, B, 2, 0, C, 2)
print *, testC
end program test

Why does gfortran give segfault error when trying to replace file?

program test
implicit none
open(100, file="a.dat", status="replace")
end program test
When I try to run this program, it runs fine the first time when the file has not been created. But an attempt to run the program again (when the file a.dat exists and should be replaced) gives segfault error. Here is what I found using gdb.
Program received signal SIGSEGV, Segmentation fault.
0x00007ff95deb1150 in strcmp () from C:\Windows\system32\msvcrt.dll
I am using GNU Fortran (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 5.1.0 with target as Target: x86_64-w64-mingw32. I didn't use any extra compiler flags except -g.
Also since gdb mentions Windows system files, here is which OS I use - Windows 8.1

Unable to build Boost libraries with GCC

I am using Windows 7 64-bit, and want to compile the non-precompiled libraries (specifically, I need Filesystem) from the command line (I do not use MSVC). I have MinGW, but read on the Boost website that MSYS shell is not supported, so I'm trying to compile the libraries from the Windows command prompt.
First of all, running bootstrap.bat results in the following error:
Building Boost.Jam build engine
'cl' is not recognized as an internal or external command,
operable program or batch file.
Failed to build Boost.Jam build engine.
Please consult bjam.log for furter diagnostics.
You can try to obtain a prebuilt binary from
http://sf.net/project/showfiles.php?group_id=7586&package_id=72941
Also, you can file an issue at http://svn.boost.org
Please attach bjam.log in that case.
Plus, there is not bjam.log file anywhere in the boost_root directory.
Disregarding this error, and trying to run the downloaded bjam.exe file, I get another error:
c:/boost_1_45_0/tools/build/v2/build\configure.jam:145: in builds-raw
*** argument error
* rule UPDATE_NOW ( targets * : log ? : ignore-minus-n ? )
* called with: ( <pbin.v2\libs\regex\build\gcc-mingw-4.5.2\debug\address-model64\architecture-x86>has_icu.exe : : ignore-minus-n : ignore-minus-q )
* extra argument ignore-minus-q
(builtin):see definition of rule 'UPDATE_NOW' being called
c:/boost_1_45_0/tools/build/v2/build\configure.jam:179: in configu
re.builds
c:/boost_1_45_0/tools/build/v2/build\configure.jam:216: in object(
check-target-builds-worker)#409.check
etc. with quite a lot of complaints. Setting the 'architecture' and 'address-model' options doesn't help.
Any suggestions?
#Andre
Following Andre's suggestion, I created minGW-bjam that was running for an hour and a half and built most of the libraries, but not the one I need at this moment: Filesystem.
Trying to compile only Filesystem, specifying version 2 with define="BOOST_FILESYSTEM_VERSION=2" and --disable-filesystem3 does not help. I get the following error:
gcc.compile.c++ bin.v2\libs\filesystem\build\gcc-mingw-4.5.2\debug\v3\src\operations.o
In file included from ./boost/filesystem/v3/operations.hpp:24:0,
from libs\filesystem\v3\src\operations.cpp:48:
./boost/filesystem/v3/config.hpp:16:5: error: #error Compiling Filesystem version 3
file with BOOST_FILESYSTEM_VERSION defined != 3
libs\filesystem\v3\src\operations.cpp:647:26: warning:
'<unnamed>::create_symbolic_link_api' defined but not used
"g++" -ftemplate-depth-128 -O0 -fno-inline -Wall -g -DBOOST_ALL_NO_LIB=1 -
DBOOST_FILESYSTEM_DYN_LINK=1 -DBOOST_FILESYSTEM_VERSION=2 -DBOOST_SYSTEM_DYN_LINK=1 -
I"." -c -o "bin.v2\libs\filesystem\build\gcc-mingw-4.5.2\debug\v3\src\operations.o"
"libs\filesystem\v3\src\operations.cpp"
etc. with a lot of ...failed statements.
Any hints here?
It's easy. Just use "bootstrap.bat gcc" to select GCC
The bootstrap script assumes the msvc compiler is available. But you can build bjam by hand without the bootstrap script:
Step into the tools\build\v2\engine\src directory and call "build.bat mingw". It will create a bjam.exe. You can then put it in your %PATH% or perhaps in the root boost directory...
To be honest, I usually build bjam like this with the msvc compiler and use this "msvc-bjam" to build my mingw boost libraries.
So... the first part of the problem was solved by Andre's suggestion.
The second part was solved by setting the variable BOOST_FILESYSTEM_VERSION to 3 everywhere (the error above complains about incompatibility with what is set in file user.hpp). Although this is not the default option for Boost 1.45 that I'm using, it's the only thing that works (i.e. bjam wants to compile version 3 no matter what). So now I have version 3 of the filesystem library, and version 2 for all others, but that doesn't seem to be an issue for the moment.
I do have a problem with using Boost with OpenCV and Eigen libraries, though... off to the next challenge ;)
Since I can't comment yet, I want to add that I ran
bootstrap mingw
to generate b2 properly and then
b2 --build-dir="c:\boost_release" toolset=gcc --build-type=complete "c:\boost_release\stage"
The includes will be located at your boost root folder (boost_1_58_00/boost) and your binaries at the specified build folder.

Resources