Skip to content
This repository was archived by the owner on Mar 4, 2019. It is now read-only.

Commit c1f7b20

Browse files
NHDalyViralBShah
authored andcommitted
Avoid need to change program.c by providing lib name. (#55)
* Avoid need to change program.c by providing name. Changes juliac.jl to provide the name of the created shared lib ("libhello") to the c preprocessor as a macro, via "-D". This way you do not need to modify the provided program.c when compiling a new julia program. Addresses issue #3. * fix: Also use macro for libname in program2.c * Update README to reflect macro defined libname. Remove references from README to changing the image name manually in `program.c`. Add note about the availability of the image lib name in the C preprocessor macro. * Rename lib-name macro variable; remove default val. s/JULIA_LIB_NAME/JULIAC_JL_PROGRAM_LIBNAME/g; Remove default value. The libname *must* be provided on the commandline via `-DJULIAC_JL_PROGRAM_LIBNAME="libname"`.
1 parent 3c0712b commit c1f7b20

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,11 @@ script into object code, and then builds it into the system image
9797
specified by the `-J` switch. This prepares an object file, which is
9898
then linked into a shared library containing the system image and user
9999
code. A driver script such as the one in `program.c` can then be used to
100-
build a binary that runs the julia code. For now, the image file has
101-
to be changed in `program.c` to match the name of the shared library
102-
containing the compiled julia program.
100+
build a binary that runs the julia code.
103101

104102
Instead of a driver script, the generated system image can be embedded
105103
into a larger program following the embedding examples and relevant
106-
sections in the Julia manual.
104+
sections in the Julia manual. Note that the name of the generated system image (`"libhello"` for `hello.jl`) is accessible from C in the preprocessor macro `JULIAC_PROGRAM_LIBNAME`.
107105

108106
With Julia 0.7, a single large binary can be created, which does not
109107
require the driver program to load the shared library. An example of

juliac.jl

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
250250
end
251251

252252
if executable
253+
push!(cflags, "-DJULIAC_PROGRAM_LIBNAME=\"lib$julia_program_basename\"")
253254
command = `$cc -m64 -o $e_file $c_program $s_file $cflags $ldflags $ldlibs`
254255
if is_apple()
255256
command = `$command -Wl,-rpath,@executable_path`

program.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ int main(int argc, char *argv[])
2222
// Initialize Julia
2323
uv_setup_args(argc, argv); // no-op on Windows
2424
libsupport_init();
25-
jl_options.image_file = "libhello";
25+
// JULIAC_PROGRAM_LIBNAME defined on command-line for compilation.
26+
jl_options.image_file = JULIAC_PROGRAM_LIBNAME;
2627
julia_init(JL_IMAGE_JULIA_HOME);
2728

2829
// Do some work

program2.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ int wmain(int argc, wchar_t *wargv[], wchar_t *envp[])
4141
// initialization
4242
libsupport_init();
4343
// jl_options.compile_enabled = JL_OPTIONS_COMPILE_OFF;
44-
jl_options.image_file = "libhello";
44+
// JULIAC_PROGRAM_LIBNAME defined on command-line for compilation.
45+
jl_options.image_file = JULIAC_PROGRAM_LIBNAME;
4546
julia_init(JL_IMAGE_JULIA_HOME);
4647

4748
// build arguments array: `String[ unsafe_string(argv[i]) for i in 1:argc ]`

0 commit comments

Comments
 (0)