Hello David, Thank you very much for your reply. I can confirm that simply including the file that contains the struct declaration is working. The problem I was facing is due to the fact that I was using a 3rd party library that had an empty stub-header file with the same name in the top-level of the library directory to prevent some other compilation/build warnings from other environments. When trying to compile my code TCC took the first file it found in the list to #include and as it was an empty file I never got the struct declarations. Unfortunately it didn’t generate an error or warning as the file was #included successfully. Thanks again for your reply! Much appreciated. Best regards, ~ Joel From: Tinycc-devel [mailto:address@hidden On Behalf Of David Mertens Sent: 27 November, 2016 13:09 To: address@hidden Subject: Re: [Tinycc-devel] libtcc using existing structs tcc_add_file() probably won't work for what you're trying to use it for. The simplest way I can think to fix this problem is to #include the file that contains the struct declaration. Hope that helps! David On Sun, Nov 6, 2016 at 11:23 AM, Joel Bodenmann <address@hidden> wrote: Hello folks,
I am successfully using libtcc to compile & link single C functions on-the-fly. Everything works great for those small C functions which don't do anything other than calling other functions which are already part of the program that uses libtcc. I simply use tcc_add_symbol() to make those functions become available to the compiled function. However, now I am facing issues when I try to compile C code that creates an instance of a struct. For example, I try to compile a C program that creates an instance of a struct named foo:
struct foo f;
the struct "foo" is part of the already compiled program (the program that uses libtcc to compile that smaller C program). The problem is that compiling using tcc_compile_string() fails with the error message: "error: unknown type size" at exactly that line. I understand that the compiler has to know the declaration of the struct foo in order to work with it, however, I fail to understand how I give TCC access to that struct declaration? I tried using supplying the header file that contains the declaration of the struct foo to TCC using tcc_add_file() but that didn't change anything at all.
I'm a bit lost at this point and I'd be thankful for any kind of help. Please excuse if I am using wrong terminology somewhere.
Best regards, ~ Joel
_______________________________________________ Tinycc-devel mailing list address@hidden https://lists.nongnu.org/mailman/listinfo/tinycc-devel
--
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." -- Brian Kernighan |