bleenco / binfs

Library for embedding binary or text files into C++ programs
MIT License
24 stars 3 forks source link

error C2026: string too big, trailing characters truncated #3

Open jonatino opened 3 years ago

jonatino commented 3 years ago

My project fails to compile when trying to embed an angular web application. Compiling VS 2019 msvc.

Here is my binfs.hpp

https://gist.github.com/Jonatino/9bd16b105c12305e2e227c7f4710cba5

jonatino commented 3 years ago

The longest string literal for my background.png image is 1,585,218 characters.

jkuri commented 3 years ago

Hi. After googling this I found out library shoud generate strings as

char *s = "very long"
          "string";

instead of

char *s = "very long string";

to make this work in VS on Windows.

@Jonatino feel free to open a pull request, otherwise I can take a look next week.

jonatino commented 3 years ago

@jkuri I think we'd need to take a step farther and chunk them into separate strings entirely; it seems msvc still enforces a 65535 byte length for even contacted strings.

See https://docs.microsoft.com/en-us/cpp/c-language/maximum-string-length?view=msvc-160#:~:text=ANSI%20compatibility%20requires%20a%20compiler,C%20is%20approximately%202%2C048%20bytes.

While an individual quoted string cannot be longer than 2048 bytes, a string literal of roughly 65535 bytes can be constructed by concatenating strings.

And I've just started C++ a few days ago. I can try to get this working if not your help would be appreciated :)

jkuri commented 3 years ago

sure, you are welcome to open a PR then we can check together.

jkuri commented 3 years ago

btw, manually converting strings to format I mentioned above make this compile on Windows if I recall correctly, maybe this lib https://github.com/ekg/split can come handy.