How to Link a Plain File into My Executable

Can I link a plain file into my executable?

You could do this:

objcopy --input binary \
--output elf32-i386 \
--binary-architecture i386 my_file.xml myfile.o

This produces an object file that you can link into your executable.
This file will contain these symbols that you'll have to declare in your C code to
be able to use them

00000550 D _binary_my_file_xml_end
00000550 A _binary_my_file_xml_size
00000000 D _binary_my_file_xml_start

Qt :How to make hyperlink to exe file

You can use this code :

QLabel *lbl = new QLabel;
lbl->setText("<a href='file:///c:/fg740p.exe'>Open</a>");
lbl->setOpenExternalLinks(true);
lbl->show();

substitute c:/fg740p.exe with the path to your .exe file.
And as you may know Open is what displayed to user.

C/C++ with GCC: Statically add resource files to executable/library

With imagemagick:

convert file.png data.h

Gives something like:

/*
data.h (PNM).
*/
static unsigned char
MagickImage[] =
{
0x50, 0x36, 0x0A, 0x23, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20,
0x77, 0x69, 0x74, 0x68, 0x20, 0x47, 0x49, 0x4D, 0x50, 0x0A, 0x32, 0x37,
0x37, 0x20, 0x31, 0x36, 0x32, 0x0A, 0x32, 0x35, 0x35, 0x0A, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,

....

For compatibility with other code you can then use either fmemopen to get a "regular" FILE * object, or alternatively std::stringstream to make an iostream. std::stringstream is not great for this though and you can of course just use a pointer anywhere you can use an iterator.

If you're using this with automake don't forget to set BUILT_SOURCES appropriately.

The nice thing about doing it this way is:

  1. You get text out, so it can be in version control and patches sensibly
  2. It is portable and well defined on every platform

How do I derive an executable name from a source file in Meson build?

It should work if you define your variable simply as array, e.g.:

my_test_files = ['test_foo.c','test_bar.c','test_baz.c']

the loop stays the same, except some typo fixed with:

foreach t_file : my_test_files
t_name = t_file.split('.')[0]
test(t_name, executable(t_name, t_file, ...))
endforeach

instead of building array of file objects. This is because executable() accepts input files in many forms: as file objects (which you tried to do) and as strings either source files (that should be compiled) or object files (to be linked) - detected by file name extension.

For more flexibility and better control, one can use array of arrays (which is, of course, extendable and may contain anything that is needed to generate tests):

foo_files = files('test_foo.c')
bar_files = files('test_bar.c')
baz_files = files('test_baz.c')

test_files = [
['foo', foo_files, foo_deps],
['bar', bar_files, []],
['baz', baz_files, baz_deps]]

foreach t : test_files
test(t[0], executable(t[0], t[1], dependencies=t[2], ...))
endforeach

qmake: compile single cpp file into an executable

To make an additional executable you can use use system() in .pro like so:

system(g++ otherapp.cpp)

Which will be built every time you call qmake. However if you want to build the additional app automatically when its source is changed, use QMAKE_EXTRA_TARGETS instead.

How can I convert a JAR file to an EXE file?

  1. See this link: Java to Exe. It also explains what valid reasons are to do this, and when you should not.

  2. You can't really encrypt binaries as the machine has to understand them. That said, an optimized executable is very difficult to decompile, while plain class files are ease.

  3. If you have an exe there are installers enough.



Related Topics



Leave a reply



Submit