How to make Unix binary self-contained?
There's CDE a bit of software designed to do exactly what you want. Here's a google tech talk about it
http://www.youtube.com/watch?v=6XdwHo1BWwY
How do I package a Go program so that it is self sufficient?
TL;DR
Your Go app is not being able to allocate virtual memory to run. I've never developed for a switch before but if it's running linux or a unix variant, check group/user permissions and ulimit values to check if that user has any kind of restriction. Maybe this question might be of help
Longer version
So, your problem here is not go not being able to run without the go development environment because you really don't need it. Go is known for generating static binaries that by definition are self contained and don't depend on other libraries to run.
If you take a better look at your error message, you'll notice that it says:
"cannot reserve arena virtual address space"
You might be asking yourself "what is this arena?"
I quick look at malloc's source code gives us a hint:
Set up the allocation arena, a contiguous area of memory where
allocated data will be found. The arena begins with a bitmap large
enough to hold 4 bits per allocated word.
If you go through that source code you'll find your error message around here.
The runtime·SysReserve C function is the one that actually tries to reserve the virtual address space for the arena. If it can't allocate that, it will throw that error.
You can find code for the Linux implementation of it here.
As go normally tries to avoid big allocations as the might fail right away, if your user can't allocate something as small as 64K, it means your user has tight restrictions. As I have no idea which OS your switch is running and have no experience developing for them I can't go any further than this.
If you can provide more information, I can try to update this answer accordingly.
How can I know if my executable will also to run on other computers (linux)?
Supply any relevant shared libraries with the executable, and set $LD_LIBRARY_PATH
in a shell script that invokes the executable to tell the linker where to find the shared libraries. See the ld.so(8)
man page for more details, and be sure to follow the appropriate licenses.
How can I make a Python script standalone executable to run without ANY dependency?
You can use py2exe as already answered and use Cython to convert your key .py
files in .pyc
, C compiled files, like .dll
in Windows and .so
on Linux.
It is much harder to revert than common .pyo
and .pyc
files (and also gain in performance!).
How to install and use make in Windows?
make
is a GNU command so the only way you can get it on Windows is installing a Windows version like the one provided by GNUWin32. Anyway, there are several options for getting that:
The most simple choice is using Chocolatey. First you need to install this package manager. Once installed you simlpy need to install
make
(you may need to run it in an elevated/admin command prompt) :choco install make
Other recommended option is installing a Windows Subsystem for Linux (WSL/WSL2), so you'll have a Linux distribution of your choice embedded in Windows 10 where you'll be able to install
make
,gcc
and all the tools you need to build C programs.For older Windows versions (MS Windows 2000 / XP / 2003 / Vista / 2008 / 7 with msvcrt.dll) you can use GnuWin32.
An outdated alternative was MinGw, but the project seems to be abandoned so it's better to go for one of the previous choices.
How to run .NET Core console application from the command line
If it's a framework-dependent application (the default), you run it by dotnet yourapp.dll
.
If it's a self-contained application, you run it using yourapp.exe
on Windows and ./yourapp
on Unix.
For more information about the differences between the two app types, see the .NET Core Application Deployment article on .NET documentation.
How do I get the directory where a Bash script is located from within the script itself?
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
is a useful one-liner which will give you the full directory name of the script no matter where it is being called from.
It will work as long as the last component of the path used to find the script is not a symlink (directory links are OK). If you also want to resolve any links to the script itself, you need a multi-line solution:
#!/usr/bin/env bash
SOURCE=${BASH_SOURCE[0]}
while [ -L "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
SOURCE=$(readlink "$SOURCE")
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
This last one will work with any combination of aliases, source
, bash -c
, symlinks, etc.
Beware: if you cd
to a different directory before running this snippet, the result may be incorrect!
Also, watch out for $CDPATH
gotchas, and stderr output side effects if the user has smartly overridden cd to redirect output to stderr instead (including escape sequences, such as when calling update_terminal_cwd >&2
on Mac). Adding >/dev/null 2>&1
at the end of your cd
command will take care of both possibilities.
To understand how it works, try running this more verbose form:
#!/usr/bin/env bash
SOURCE=${BASH_SOURCE[0]}
while [ -L "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
TARGET=$(readlink "$SOURCE")
if [[ $TARGET == /* ]]; then
echo "SOURCE '$SOURCE' is an absolute symlink to '$TARGET'"
SOURCE=$TARGET
else
DIR=$( dirname "$SOURCE" )
echo "SOURCE '$SOURCE' is a relative symlink to '$TARGET' (relative to '$DIR')"
SOURCE=$DIR/$TARGET # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
fi
done
echo "SOURCE is '$SOURCE'"
RDIR=$( dirname "$SOURCE" )
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
if [ "$DIR" != "$RDIR" ]; then
echo "DIR '$RDIR' resolves to '$DIR'"
fi
echo "DIR is '$DIR'"
And it will print something like:
SOURCE './scriptdir.sh' is a relative symlink to 'sym2/scriptdir.sh' (relative to '.')
SOURCE is './sym2/scriptdir.sh'
DIR './sym2' resolves to '/home/ubuntu/dotfiles/fo fo/real/real1/real2'
DIR is '/home/ubuntu/dotfiles/fo fo/real/real1/real2'
Is there any sed like utility for cmd.exe?
Today powershell saved me.
For grep
there is:
get-content somefile.txt | where { $_ -match "expression"}
or
select-string somefile.txt -pattern "expression"
and for sed
there is:
get-content somefile.txt | %{$_ -replace "expression","replace"}
For more detail about replace PowerShell function see this Microsoft article.
Related Topics
What Is The Safest Way to Empty a Directory in *Nix
How to Set Pthread CPU Affinity in Os X
Understanding The Getting of Task_Struct Pointer from Process Kernel Stack
How to Use Performance Counters Inside of The Kernel
User-Space Memory Editing Programs
Using Dma Memory Transfer in User-Space
Does Each Unix File Description Have Its Own Read/Write Buffers
Is Overwriting a Small File Atomic on Ext4
Sending from The Same Udp Socket in Multiple Threads
How to Pass Local Variable to Remote Using Ssh and Bash Script
How to Efficiently Move Many Files to a New Server
Why Does The Solaris Assembler Generate Different Machine Code Than The Gnu Assembler Here
Reading Serial Port Blocks for Unknown Reason
Installing 32 Bit Libraries (Glibc) on 64 Bit Rhel Without Using Yum