Skip to content

Instantly share code, notes, and snippets.

@giordano
Last active February 13, 2021 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giordano/87218e88a5d6943223b306a0443e52a8 to your computer and use it in GitHub Desktop.
Save giordano/87218e88a5d6943223b306a0443e52a8 to your computer and use it in GitHub Desktop.
Embedding Julia in C++ on CentOS 7
FROM centos:7
RUN yum install -y gcc gcc-c++ make
RUN curl -sL "https://julialang-s3.julialang.org/bin/linux/x64/1.5/julia-1.5.3-linux-x86_64.tar.gz" | tar xzf - -C /usr/local --strip-components=1
COPY embed_example.cpp Makefile /root/
WORKDIR "/root"
#include <julia.h>
#include <string>
int main(int argc, char *argv[])
{
std::string teststr = "abc";
/* required: setup the Julia context */
jl_init();
jl_value_t* ans = jl_eval_string("println(sqrt(2.0))");
jl_atexit_hook(0);
return 0;
}
JL_SHARE = $(shell julia -E 'joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia")')
LIBSTDCXX = $(shell julia -E 'joinpath(dirname(Sys.BINDIR), "lib", "julia", "libstdc++.so.6")')
LIBGCC_S = $(shell julia -E 'joinpath(dirname(Sys.BINDIR), "lib", "julia", "libgcc_s.so.1")')
CFLAGS += $(shell $(JL_SHARE)/julia-config.jl --cflags)
CXXFLAGS += $(shell $(JL_SHARE)/julia-config.jl --cflags)
LDFLAGS += $(shell $(JL_SHARE)/julia-config.jl --ldflags)
LDLIBS += $(shell $(JL_SHARE)/julia-config.jl --ldlibs) -nodefaultlibs $(LIBSTDCXX) -lc $(LIBGCC_S)
all: embed_example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment