Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Michael S Newsgroups: comp.lang.c Subject: Re: C23 thoughts and opinions Date: Thu, 30 May 2024 17:51:07 +0300 Organization: A noiseless patient Spider Lines: 53 Message-ID: <20240530175107.00001dc2@yahoo.com> References: <00297443-2fee-48d4-81a0-9ff6ae6481e4@gmail.com> <87msoh5uh6.fsf@nosuchdomain.example.com> <87y18047jk.fsf@nosuchdomain.example.com> <87msoe1xxo.fsf@nosuchdomain.example.com> <87ikz11osy.fsf@nosuchdomain.example.com> <20240530170836.00005fa0@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Date: Thu, 30 May 2024 16:50:57 +0200 (CEST) Injection-Info: dont-email.me; posting-host="da80087394b39f0dc93ab771f1b9ace1"; logging-data="1754093"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19l+7bBVIOeapXcNwdPy8FC/p/knZEs4gs=" Cancel-Lock: sha1:rqj5/q7wUNxMaiiIT2n9LRqVcQQ= X-Newsreader: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-w64-mingw32) Bytes: 3748 On Thu, 30 May 2024 17:08:36 +0300 Michael S wrote: > On Thu, 30 May 2024 14:34:00 +0100 > bart wrote: > > > On 30/05/2024 03:32, Lawrence D'Oliveiro wrote: > > > On Wed, 29 May 2024 13:58:20 +0200, Bonita Montero wrote: > > > > > >> I've got a small commandline-tool that makes a const'd char > > >> -array from any binary file. > > > > > > It seems to me it would be more efficient to use objcopy to turn > > > that binary file directly into an object file with symbols > > > accessible from C code defining its beginning and ending points. > > > Then just link it into the executable. > > > > None of my compilers, whether for C or anything else, generate > > object files. > > > > However, suppose I wanted to link a file called 'logo.bmp' say, into > > my program, which consisted of a file called main.c. > > > > What is the entire process using your suggestion? What do I put > > into main.c? Assume the data is represented by a char-array. > > > > extern unsigned char _binary_logo_bmp_start[]; > extern unsigned char _binary_logo_bmp_size[]; > > The first symbol is an array itself. > The seconded symbol contains the length of array. You use it in > somewhat non-intuitive way: > size_t my_size = (size_t)_binary_logo_bmp_size; > > Pay attention that I never used this method myself, just took a look > at the output of objcopy with 'objdump -t', so please don't take my > words as a sure thing. > > BTW, options in this case are rather simple: > objcopy -I binary -O elf32-little logo.bmp logo_bmp.o > Replace elf32-little with relevant format for your software. However I > am not sure that it would work for none-elf output formats. > Tested it. On msys2 it can produce correct pe-x86-64 format but does it in counter-intuitive way: you have to ask for elf64-x86-64 instead of pe-x86-64. I don't know why it works like that. The rest of what I wrote above was correct.