[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] Libtcc and existing variables

From: Joel Bodenmann
Subject: [Tinycc-devel] Libtcc and existing variables
Date: Wed, 27 Sep 2017 12:47:13 +0200
User-agent: Zoho Mail

Hello folks,


I am successfully using libtcc in an application. I’m very happy with it and I thank you for providing this awesome tool.

So far, my needs were basically completely covered by the libtcc_test.c example program that uses tcc_add_symbol() to give the compiled program access to a function that exists in the host application (I’m sorry if my terminology is off here). However, now I have a case where I need to give the client application (the program that gets compiled) access to a variable that already exists in the host application. Specifically, my client program needs a pointer to a struct that already exists in the host application during runtime. This is a basic illustration of what’s going on:


// Struct declaration (known in the host program and the client program)

typedef struct myStruct_t {


} myStruct;


// Creating an instance of said struct in the host program

myStruct a;


// Using that struct in the client program (this gets compiled by libtcc)



When I compile this with libtcc, I get the compilation error “a is undeclared”. Initially I was confused by that because I properly added the struct instance using this:   tcc_add_symbol(s, “a”, &a);

However, upon thinking about it (and reading the documentation) I figured out that tcc_add_symbol only affects linking time and the tcc compiler simply doesn’t know what a is.


My question: Is there any way to give a client program access to a variable that exists in the host program? All I could think of so far is generating a wrapper function that gets compiled with the client program that returns a pointer to a. However, I’d like to avoid that if possible.


Any kind of comments would be greatly appreciated.



Best regards,

~ Joel Bodenmann

reply via email to

[Prev in Thread] Current Thread [Next in Thread]