How can I produce a Crystal executable with no dependencies?

Sod Almighty

I'm writing a program in Crystal, that I intend to compile and move to other systems for execution. Ideally, it should have no dependencies, as the target systems will be fresh installations of linux.

Sadly, I can't get around the libc dependency, so I will presumably have to compile the executable on a system possessing the lowest version of libc I wish to target. I figure it should be forward-compatible.

I'm having difficulty with libssl, however. Default installations of Debian Wheezy don't seem to come with libssl, so I get this error when running my executable:

error while loading shared libraries: libssl.so.1.0.0:
cannot open shared object file: No such file or directory

I assume this dependency exists because I require "http/client" in my source. However, I make no ssl-related calls, as I only use it to connect to unsecured websites.

I apparently also have a dependency on libevent-2.0.so.5. Presumably all Crystal programs do. Who knows how many other dependencies Crystal has?

My executables have to run on a freshly-installed linux system. So, how can I produce a Crystal executable with no dependencies? Other than libc, I suppose.

waj

In Linux, you can list the shared libraries that an executable needs using the ldd command. In OSX, otool -L could be used for the same purpose.

Normally, the linker will use shared libraries while building the executable if it can find them. So, what you need to do, is force the linker to use static libraries instead. (In the future we might add a flag to the compiler to force this choice)

You should find some of these static libraries in /opt/crystal/embedded/lib. We use these to generate a portable Crystal compiler.

In order to use these libraries you can run:

$ LIBRARY_PATH=/opt/crystal/embedded/lib crystal build my_app.cr

That should prefer libraries available in that directory before considering others installed in the standard locations.

Unfortunately, OpenSSL is not distributed with Crystal, so you must either copy or build a static version of libssl and libcrypto. It's a common library anyway, available in any Linux distribution.

Regarding libc, that's more tricky. We compile the Crystal binary for releases using old CentOS and Debian distributions to make it compatible with many more libc versions.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How can I create an executable jar without dependencies using Maven?

From Java

How can I create an executable JAR with dependencies using Maven?

From Dev

How can I create an executable/runnable JAR with dependencies using Maven?

From Java

How to produce an executable jar file with all maven dependencies?

From Dev

Can I create an executable Python zip archive with dependencies?

From Java

How do I create an executable fat jar with Gradle with implementation dependencies

From Dev

How can I produce a Task<Task> to Unwrap

From Dev

How can I produce this graphic in RShiny?

From Dev

How can I produce the exact decimal values

From Dev

How can I run executable in shell script?

From Dev

How can I find the executable path of php?

From Dev

How can I make a .jar file executable?

From Dev

How can I create an executable in Linux (beginner)?

From Dev

How can I make /tmp executable?

From Dev

How can I make a script executable?

From Dev

How to detect missing dependencies for an executable?

From Dev

How can I determine build dependencies automatically?

From Dev

How I can list all sbt dependencies?

From Dev

Hilt - How can I inject dependencies into adapter?

From

How can I force gradle to redownload dependencies?

From Dev

How can I avoid dependencies between methods?

From Java

How can I specify JUnit test dependencies?

From Dev

How can I group target dependencies in CMake?

From Java

How can I visualize jar (not plugin) dependencies?

From Dev

How can I use SimpleSC with Dependencies in NSIS

From Dev

How can I add dependencies to kotlinCompilerClasspath?

From Dev

How can I import dependencies in flutter web?

From Dev

How can i add ProGuard to project with dependencies?

From Dev

How can I fix unmet dependencies - react?

Related Related

  1. 1

    How can I create an executable jar without dependencies using Maven?

  2. 2

    How can I create an executable JAR with dependencies using Maven?

  3. 3

    How can I create an executable/runnable JAR with dependencies using Maven?

  4. 4

    How to produce an executable jar file with all maven dependencies?

  5. 5

    Can I create an executable Python zip archive with dependencies?

  6. 6

    How do I create an executable fat jar with Gradle with implementation dependencies

  7. 7

    How can I produce a Task<Task> to Unwrap

  8. 8

    How can I produce this graphic in RShiny?

  9. 9

    How can I produce the exact decimal values

  10. 10

    How can I run executable in shell script?

  11. 11

    How can I find the executable path of php?

  12. 12

    How can I make a .jar file executable?

  13. 13

    How can I create an executable in Linux (beginner)?

  14. 14

    How can I make /tmp executable?

  15. 15

    How can I make a script executable?

  16. 16

    How to detect missing dependencies for an executable?

  17. 17

    How can I determine build dependencies automatically?

  18. 18

    How I can list all sbt dependencies?

  19. 19

    Hilt - How can I inject dependencies into adapter?

  20. 20

    How can I force gradle to redownload dependencies?

  21. 21

    How can I avoid dependencies between methods?

  22. 22

    How can I specify JUnit test dependencies?

  23. 23

    How can I group target dependencies in CMake?

  24. 24

    How can I visualize jar (not plugin) dependencies?

  25. 25

    How can I use SimpleSC with Dependencies in NSIS

  26. 26

    How can I add dependencies to kotlinCompilerClasspath?

  27. 27

    How can I import dependencies in flutter web?

  28. 28

    How can i add ProGuard to project with dependencies?

  29. 29

    How can I fix unmet dependencies - react?

HotTag

Archive