{"id":28187702,"url":"https://github.com/gilzoide/file2c","last_synced_at":"2026-04-13T02:02:28.875Z","repository":{"id":261666510,"uuid":"884981210","full_name":"gilzoide/file2c","owner":"gilzoide","description":"Python script that generates C source files with global variables embedding binary/text file contents, with easy integration for CMake projects","archived":false,"fork":false,"pushed_at":"2025-04-28T01:51:45.000Z","size":9,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-15T21:41:13.088Z","etag":null,"topics":["bin2c","c","cmake","cmake-module","cpp","embed-file","source-code-generation","source-code-generator","source-generation","source-generator"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gilzoide.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["gilzoide"],"patreon":null,"open_collective":null,"ko_fi":"gilzoide","tidelift":null,"community_bridge":null,"liberapay":"gilzoide","issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"thanks_dev":null,"custom":null}},"created_at":"2024-11-07T18:26:38.000Z","updated_at":"2025-12-21T00:43:41.000Z","dependencies_parsed_at":"2024-11-07T19:42:53.639Z","dependency_job_id":"c5789aa1-fc54-4431-95f3-780c10031f30","html_url":"https://github.com/gilzoide/file2c","commit_stats":null,"previous_names":["gilzoide/file2c.py"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gilzoide/file2c","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Ffile2c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Ffile2c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Ffile2c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Ffile2c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gilzoide","download_url":"https://codeload.github.com/gilzoide/file2c/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Ffile2c/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31736723,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-12T22:19:12.206Z","status":"online","status_checked_at":"2026-04-13T02:00:06.623Z","response_time":93,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bin2c","c","cmake","cmake-module","cpp","embed-file","source-code-generation","source-code-generator","source-generation","source-generator"],"created_at":"2025-05-16T08:10:29.768Z","updated_at":"2026-04-13T02:02:28.854Z","avatar_url":"https://github.com/gilzoide.png","language":"Python","readme":"# file2c\nPython script that generates C source files with global variables embedding binary/text file contents, with easy integration for CMake projects.\n\n\n## Features\n- Single executable Python script, easy to install/copy or use as Git submodule\n- Works as both a CLI script and as a Python module\n- Supports embedding files as binary or text\n  + Binary file contents have `const unsigned char *` type\n  + Text file contents have `const char *` type and are guaranteed to be null-terminated\n- File content size is available as an additional global variable\n- Generated header is compatible with both C and C++\n- [file2c.cmake](file2c.cmake) script for easy integration with CMake projects\n\n\n## Usage\n```\npython file2c.py INPUT [-o OUTPUT] [-s SYMBOL] [--text] [--header]\n```\n\n\n## Examples\n```sh\n# Generate `file.c` and `file.h` from binary contents of `file.txt`:\n#   `const unsigned char *file`: file contents as a byte string\n#   `const size_t file_size`: file size\npython file2c.py file.txt -o file.c\npython file2c.py file.txt -o file.h --header\n\n# Generate `file.c` and `file.h` from text contents of `file.txt`:\n#   `const char *file`: file contents as a null-terminated char string\n#   `const size_t file_size`: file size\npython file2c.py file.txt --text -o file.c\npython file2c.py file.txt --text -o file.h --header\n\n# Generate `file.c` and `file.h` from binary contents of `file.txt`,\n# customizing the variable symbol name to \"contents\":\n#   `const unsigned char *contents`: file contents as a byte string\n#   `const size_t contents_size`: file size\npython file2c.py file.txt --symbol contents -o file.c\npython file2c.py file.txt --symbol contents -o file.h --header\n```\n\n\n## Integrating with CMake\nIn CMake:\n```cmake\n# 1. Include file2c.cmake script\ninclude(path/to/file2c.cmake)\n\n# 2. Generate C library\nadd_file2c(\n  new_library_target\n  INPUT input_file_to_be_embedded\n  # Optional: choose the name of the global variable/header file\n  # Defaults to input file name\n  SYMBOL some_c_symbol\n  # Pass \"TEXT\" to embed contents as text, omit for binary contents\n  TEXT\n)\n\n# 3. Link the generated library with other targets\ntarget_link_libraries(my_existing_target new_library_target)\n```\n\nIn C/C++:\n```c\n// 1. Include generated header\n#include \u003csome_c_symbol.h\u003e\n\n// 2. Use the embedded contents\nvoid print_contents() {\n  printf(\"Content: %s\\n\", some_c_symbol);\n  printf(\"Size: %lu\\n\", some_c_symbol_size);\n}\n```\n","funding_links":["https://github.com/sponsors/gilzoide","https://ko-fi.com/gilzoide","https://liberapay.com/gilzoide"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgilzoide%2Ffile2c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgilzoide%2Ffile2c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgilzoide%2Ffile2c/lists"}