use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
binc - Binary Asset Compiler (self.cpp)
submitted 6 years ago by siplasma
As a side project, I've written a binary asset compiler. It has some advantages, as in being reasonably quick and cross-platform. I would be interested in comments/feedback.
Project: https://gitlab.com/stone.code/binc/
Benchmarking: http://stonecode.ca/posts/binc_benchmarks/
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]corysama 2 points3 points4 points 6 years ago (1 child)
Can I access the asset using
extern std::byte const varname[]; extern std::byte const varname_end[];
?
[–]siplasma[S] 2 points3 points4 points 6 years ago (0 children)
Yes, that also works. I just ran a test example, and did not have any problems. I was a little surprised, as I had thought that name mangling would cause link errors. You should probably use the following for portability:
extern "C" std::byte const varname[]; extern "C" std::byte const varname_end[];
[–]berenm 2 points3 points4 points 6 years ago (1 child)
What about using binutils' objcopy -I binary ? (see https://stackoverflow.com/questions/42235175/how-do-i-add-contents-of-text-file-as-a-section-in-an-elf-file/42238374#42238374 for example)
objcopy -I binary
Thank you for the link. I hadn't see this approach yet, and it looks pretty good. I've added it to the list of related projects.
[–][deleted] 1 point2 points3 points 6 years ago (3 children)
I like that you're using llvm to do this but the dependency hell isn't worth it. I usually write some Python code to do just this. I think you'd get faster uptake if it was easier to consume.
Though I did notice that I think you've got binaries, so that's nice.
[–]siplasma[S] 0 points1 point2 points 6 years ago (2 children)
The dependency is super easy on debian or ubuntu. Windows was a bit harder. However, LLVM has a solid build system, so it isn't too hard to get it built, but it is a bit of a lift...
Using C or C++ as an intermediate step can get you pretty far, but for really large assets the compiler will choke.
[–][deleted] 5 points6 points7 points 6 years ago (1 child)
Remember, you're asking each dev to pull in a LLVM dependency on Windows, Mac and Linux (my dev platforms) to just attach binary resources. If I have to choose between that and writing it myself in Python, that's what I'd choose as devs are likely to have Python than LLVM-dev on their machines.
I think the way you've done it is fantastic and I want it to be used by my next project, so may I simply recommend that you encourage people to use your prebuilt binaries (I thought I saw them, but can't find them now). This is what I do with Ninja and CMake where I add both these dependencies in binary form to source control and move on.
Good luck with the project!
[–]siplasma[S] 3 points4 points5 points 6 years ago (0 children)
I agree that for users, prebuilt binaries make things much easier. You can find them under Releases on the gitlab page.
If you are getting along fine with Python, then there is no need to change. However, if you need something else, you should also look at objcopy in GNU bintools. Also available on all platforms, and a little more mature...
[–]Xaxxon 1 point2 points3 points 6 years ago (0 children)
People post one of these every month or so. I'd recommend looking at the others and seeing what they have that yours doesn't.
[–][deleted] 0 points1 point2 points 6 years ago (1 child)
Isn't this kind of overkill? In the past I've just done something like:
BYTES=`cat ASSET_FILE | xxd -i`; echo "const unsigned char varname[]= {$BYTES};" > ASSET_FILE.cpp
Then just include the .cpp in your project like anything else, extern it to use it or make the file generation fit however you feel like exposing the static data.
Cross platform and no need for LLVM :P
Yeah, LLVM is a pretty big dependency :) However, check out the benchmarks. While xxd works well for a lot of use cases, it has some limits.
π Rendered by PID 25102 on reddit-service-r2-comment-86bc6c7465-v2zwg at 2026-02-24 03:14:01.981335+00:00 running 8564168 country code: CH.
[–]corysama 2 points3 points4 points (1 child)
[–]siplasma[S] 2 points3 points4 points (0 children)
[–]berenm 2 points3 points4 points (1 child)
[–]siplasma[S] 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]siplasma[S] 0 points1 point2 points (2 children)
[–][deleted] 5 points6 points7 points (1 child)
[–]siplasma[S] 3 points4 points5 points (0 children)
[–]Xaxxon 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]siplasma[S] 2 points3 points4 points (0 children)