linux - C++ Stand-alone executable -
i'm writing program in c++ requires file in current directory, want distribute 1 executable. love2d uses distribution method games create .love
file , use cat
combine love2d
binary , .love
file (eg. cat love2d awesomegame.love > awesomegame
). how can write program can use information @ end of itself, , extract out file.
--- update ---
thanks wonderful @dawid, have got working in cleaner method suggested (see answer if want way). here final source code:
#include <fstream> #include "ncat.h" using namespace std; int main () { ofstream ofile("ncat.exe", ios_base::out | ios_base::binary); (unsigned long = 0 ; < ncat_exe_len; ++i) ofile << ncat_exe[i]; ofile.close(); return 0; }
here's (binary) file i'm using: https://www.dropbox.com/s/21wps8usaqgthah/ncat.exe?dl=0
you can use xxd
tool. can dump binary hex in c style include header.
eg.
> echo test > > xxd -i > a.h > cat a.h unsigned char a[] = { 0x74, 0x65, 0x73, 0x74, 0x0a }; unsigned int a_len = 5;
then include header , use a
, a_len
.
example:
before build:
xxd -i _file_name_ > _file_name_.h
in program:
#include "_file_name_.h" void foo() { std::ofstream file ("output.txt", std::ios_base::out | std::ios_base::binary); file << _file_name_; // believe array named after source file }
Comments
Post a Comment