U++ framework
Do not panic. Ask here before giving up.

Home » Developing U++ » UppHub » New Tiny C Compiler Package
New Tiny C Compiler Package [message #22201] Wed, 24 June 2009 08:21 Go to next message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
Hello all

New Tcc package is available in Bazaar svn.

This package lets Upp users to use C as a scripting language.

It is also included a Tcc Demo Gui package to test it. Here I inclose a screenshot:

index.php?t=getfile&id=1813&private=0

It has been tested in Linux (Gcc) and Windows (MinGW and Msc).

Documentation is included with introduction, methods reference, a documented sample and implementation details.

Best regards
Koldo


Best regards
Iñaki
Re: New Tiny C Compiler Package [message #22244 is a reply to message #22201] Fri, 26 June 2009 19:09 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Could you please tell if there is simple way to call "embedded" binary's functions from this c-style script? Is it what you mean by "external" function in the example above?

[Updated on: Fri, 26 June 2009 19:10]

Report message to a moderator

Re: New Tiny C Compiler Package [message #22262 is a reply to message #22244] Sun, 28 June 2009 16:28 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
Hello Pavel

From the scripting file you just have to declare and call the function in simple C.

For example lets consider function plus() that is defined in the main program.

In the scripting program it would be:

double plus(double a, double b);	// External function has to be declared

...

	for (i = 0; i < 10000000; ++i)
		ret += 0.000000001*pow2(sqrt(plus(a, 10))); // plus() is called here

...


And in the main program it would be:

// Function to be called from the scripting program is defined here
double plus(double a, double b)
{
    return a + b;
} 

...
	    tcc.AddSymbol("plus", (void *)&plus); // And here we link the library function to the scripting program
...


Best regards
Koldo


Best regards
Iñaki
Re: New Tiny C Compiler Package [message #22322 is a reply to message #22262] Fri, 03 July 2009 16:50 Go to previous messageGo to next message
ptDev is currently offline  ptDev
Messages: 25
Registered: June 2009
Promising Member
I tried the Tcc Gui Demo (didn't even change the source code) and the "Compile and Run" button didn't respond.

I just built the Tcc package before trying the demo, What else do I need to do? Am I doing anything wrong?

[Updated on: Fri, 03 July 2009 16:50]

Report message to a moderator

Re: New Tiny C Compiler Package [message #22323 is a reply to message #22322] Fri, 03 July 2009 18:02 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
Hello ptDev

Copy the file libtcc.dll to "C:\WINDOWS\System" or change in main.cpp

Tcc tcc;

for

Tcc tcc("libtcc.dll location with full path");

It was my fault: I did not documented that clearly and I left Tcc tcc; outside the try {} block in main.cpp so that the exception caused for not finding the libtcc.dll was not catched.

Best regards
Koldo


Best regards
Iñaki
Re: New Tiny C Compiler Package [message #22332 is a reply to message #22323] Sat, 04 July 2009 08:58 Go to previous messageGo to next message
ptDev is currently offline  ptDev
Messages: 25
Registered: June 2009
Promising Member
Hi,

I tried again, with libtcc compiled from source with MinGW. Despite building a DLL from there and copying this DLL to the windows path, it still wouldn't work. (It's not recognized as a valid win32 DLL).

How can I make this work with MinGW?
Re: New Tiny C Compiler Package [message #22333 is a reply to message #22332] Sat, 04 July 2009 11:06 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 740
Registered: November 2008
Location: France
Contributor
Hi,

'Tcc Gui Demo' works fine in linux Smile
except for one small thing ...The project name: 'Tcc Gui Demo' contains spaces and Upp tries to launch 'Tcc' instead of 'Tcc Gui Demo' which of course does not existe.

This may work on windows but i think avoiding spaces in names is a good precaution

This Tcc wrapper will become very handy, thanks.

Didier


Re: New Tiny C Compiler Package [message #22415 is a reply to message #22333] Mon, 13 July 2009 09:25 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
Hello Didier

Thank you for your feedback.

I am surprised as I have put in Bazaar more packages with spaces like:
- OfficeAutomation demo console
- PainterSvg demo
- SysInfo demo console

Perhaps simply nobody has used them in Linux Smile
I use Ubuntu without problems.

If nobody answer I will change all package names to avoid spaces.

Best regards
Koldo


Best regards
Iñaki
Re: New Tiny C Compiler Package [message #22416 is a reply to message #22415] Mon, 13 July 2009 10:06 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 740
Registered: November 2008
Location: France
Contributor
Hello Koldo,

I confirm, 'PaiterSvg Demo' & 'SysInfo demo console' have the same problem.
I never tried them before. Rolling Eyes

As for 'OfficeAutomation demo console': it doesn't compile on linux

Re: New Tiny C Compiler Package [message #22417 is a reply to message #22416] Mon, 13 July 2009 10:44 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
Didier wrote on Mon, 13 July 2009 10:06

Hello Koldo,

I confirm, 'PaiterSvg Demo' & 'SysInfo demo console' have the same problem.
I never tried them before. Rolling Eyes

As for 'OfficeAutomation demo console': it doesn't compile on linux




Ok Didier

I will change package names aujourd'hui.

Best regards
Koldo


Best regards
Iñaki
Re: New Tiny C Compiler Package [message #22446 is a reply to message #22332] Wed, 15 July 2009 23:28 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
ptDev wrote on Sat, 04 July 2009 08:58

Hi,

I tried again, with libtcc compiled from source with MinGW. Despite building a DLL from there and copying this DLL to the windows path, it still wouldn't work. (It's not recognized as a valid win32 DLL).

How can I make this work with MinGW?


Hello ptDev

The fastest way for you is just copying the libtcc.dll file in \bazaar\Tcc into \windows\system or indicate the libtcc.dll location in the Tcc constructor, so instead of doing:

Tcc tcc;

you would do:

Tcc tcc("c:\\myFolder\\libtcc.dll");

If you prefer to compile it by yourself please give the compiling details to see what happen.

Best regards
Koldo


Best regards
Iñaki
Re: New Tiny C Compiler Package [message #22721 is a reply to message #22446] Sat, 08 August 2009 17:28 Go to previous messageGo to next message
kasome is currently offline  kasome
Messages: 78
Registered: July 2008
Location: Taiwan
Member
The Tiny C Compiler Package is nice....

Could I save the compiled result as an executable file ?

for example,
String program = tcc.GetProgram();
StoreToFile( program, "program.exe" );
Re: New Tiny C Compiler Package [message #22729 is a reply to message #22721] Sun, 09 August 2009 17:30 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
kasome wrote on Sat, 08 August 2009 17:28

The Tiny C Compiler Package is nice....

Could I save the compiled result as an executable file ?

for example,
String program = tcc.GetProgram();
StoreToFile( program, "program.exe" );


Hello Kasome

Yes, no problem.
Let me some days to add it.

Best regards
Koldo


Best regards
Iñaki
Re: New Tiny C Compiler Package [message #22769 is a reply to message #22201] Wed, 12 August 2009 23:46 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
Hello Kasome

It is ready, tested in WinXP and Ubuntu, documented and submitted to Bazaar.

The demo program has been adapted to include this option.

It can output native executable files in Linux and Windows, I mean, when compiling the main program under Linux the executable optained will be Linux native (ELF format), and when compiling it in Windows the executable will be Windows native (PE-COFF format).

This way the output program can be simply called and run for example from a terminal.

The main visible changes are in:

void SetOutputExe();
void SetOutputMemory();
	
void Link(const char *fileName = 0);


This fileName is the executable file.

Please read the instructions before using it.

Best regards
Koldo


Best regards
Iñaki
Re: New Tiny C Compiler Package [message #22771 is a reply to message #22201] Thu, 13 August 2009 08:34 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
Hello

Two additional things:

- In Linux
To get the executable file you will need to install tcc in the system. It is just from a terminal in Tcc/lib folder running make & make install

- In Windows
Supplied .dll has been updated, so to get the .exe files you would have to use it
If you want to recompile it by yourself it is easier than before. Now you do not need MSYS. With MinGW in the PATH it is enough using the GetDLL.bat file.
The .dll is bigger than before. Just becuase it is compiled now using -O3 with MinGW 4.4.0.

- Now error messages are in different languages, so if you want them in yours please send me the translations

Best regards
Koldo


Best regards
Iñaki
Re: New Tiny C Compiler Package [message #22781 is a reply to message #22771] Fri, 14 August 2009 14:34 Go to previous messageGo to next message
kasome is currently offline  kasome
Messages: 78
Registered: July 2008
Location: Taiwan
Member
Sorry for the delay replying.

Wow!Razz It's perfect. Thanks, koldo.
Re: New Tiny C Compiler Package [message #26433 is a reply to message #22781] Sat, 01 May 2010 12:59 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 740
Registered: November 2008
Location: France
Contributor
Hi Koldo,

I've been using Tcc package lately and you introduced a linux regression in SVN 1500 ( 8 month ago Wink ):

In Tcc/libtcc.c you changed:
#ifdef __unix__
#include "lib/Tcc.c"
#endif


Instead of:
#ifdef __unix__
#include "lib/tcc.c"
#endif


Since unix like systems are case aware, and that the filename is "tcc.c" ==> this doesn't compile any more.


I also have a very small correction for you:
In Tcc/Tcc.cpp L201:

instead of:
	unsigned long val;

Put:
	unsigned long val = 0;


This will allow testing if the symbol was found or not.


QUESTION:

Is there a reason for having a separated makefile for the Tcc lib. What I'm thinking about is allowing STATIC linking of this lib just like any other Upp package ?
This would keep from having to install the tcc lib before using the Tcc package

[Updated on: Sat, 01 May 2010 13:40]

Report message to a moderator

Re: New Tiny C Compiler Package [message #26444 is a reply to message #26433] Sun, 02 May 2010 19:53 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
Hello Didier

Thank you for your comments. They are now added. For any reason I did not know the x11 emulator I use does not care about file name case.

About the question, I did not understand it well. However I have activated not to include stdlib lib so that now it is not necessary to have tcc package installed. However please test it in your environment if it is ok.

Please any other tcc users confirm me if this change affects you.


Best regards
Iñaki
icon14.gif  Re: New Tiny C Compiler Package [message #26445 is a reply to message #26444] Sun, 02 May 2010 23:15 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 740
Registered: November 2008
Location: France
Contributor
Hi Koldo,

Thanks for the quick reply. I gonna try you're modifications right away....


OK, works Fine Cool

All compiles OK and the TCC lib isn't needed any more Thumbs Up , I can now use my small app on several computers !

Thanks
Re: New Tiny C Compiler Package [message #26446 is a reply to message #26445] Mon, 03 May 2010 08:22 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
Excellent Didier Smile

Anyway I will investigate why stdlib is included in a separate .a lib instead of being statically compiled with rest of tcc.


Best regards
Iñaki
Re: New Tiny C Compiler Package [message #26451 is a reply to message #26446] Mon, 03 May 2010 21:27 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
Hello all

I have added the possibility of choosing stdlib folder in constructor and NoStdlib() to refuse to use it.

A tcc stdlib file is in In Tcc/lib/lib/libtcc1.a

Please try it and tell me if it is ok.

Demo is also adapted.

index.php?t=getfile&id=2512&private=0
  • Attachment: dib.png
    (Size: 47.40KB, Downloaded 1947 times)


Best regards
Iñaki
Re: New Tiny C Compiler Package [message #26452 is a reply to message #26446] Mon, 03 May 2010 22:28 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 740
Registered: November 2008
Location: France
Contributor
Hi Koldo,

why stdlib is included in a separate .a lib instead of being statically compiled with rest of tcc.


Before sending the previous post I made some tests myself, and the problem is not really dependent on the stdlib.

In the tccelf.c file L1031, the stdlib is requested ... but not only: An explicit link to /usr/local/lib/tcc/libtcc1.a is made.
==> If this file is not present on the system then an exception is thrown Confused
==> So although everything needed was compiled and linked, the program refuse to execute. if you comment L1031 & L1032 everything works fine.
I don't know why this has been done, but for our particular usage it's not good.
Re: New Tiny C Compiler Package [message #26455 is a reply to message #26452] Tue, 04 May 2010 09:24 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
Didier wrote on Mon, 03 May 2010 22:28

Hi Koldo,

why stdlib is included in a separate .a lib instead of being statically compiled with rest of tcc.


Before sending the previous post I made some tests myself, and the problem is not really dependent on the stdlib.

In the tccelf.c file L1031, the stdlib is requested ... but not only: An explicit link to /usr/local/lib/tcc/libtcc1.a is made.
==> If this file is not present on the system then an exception is thrown Confused
==> So although everything needed was compiled and linked, the program refuse to execute. if you comment L1031 & L1032 everything works fine.
I don't know why this has been done, but for our particular usage it's not good.



Hello Didier

In last change sent yesterday I have added two patches:

- NoStdlib() function

void NoStdlib(TCCState *s) {
	s->nostdlib = 1;
}


This effectively avoids to try to load libtcc1.a, as in tccelf.c you can see this:

    if (!s1->nostdlib) {
        tcc_add_library(s1, "c");

        snprintf(buf, sizeof(buf), "%s/%s", tcc_lib_path, "libtcc1.a");
        tcc_add_file(s1, buf);
    }


- For linux, constructor is now Tcc::Tcc(const char *libPath).

libPath is assigned to tcc_lib_path. This way you can put libtcc1.a wherever you want, instead of in "/usr/local/lib/tcc".

For convenience it is included in Tcc/lib/lib a copy of libtcc1.a file.

You can try both options, or using NoStdlib(), or using libtcc1.a file indicating in constructor in what folder it is (you do not need to install tcc, you just need to indicate where libtcc1.a is)


Best regards
Iñaki
TCC package broken [message #34038 is a reply to message #26455] Wed, 12 October 2011 22:57 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 740
Registered: November 2008
Location: France
Contributor
Hi Koldo,

The TCC package is broken since the tcc plugin was introduced.
The following corrections make it compile again (at least under linux):
* the plugin/tcc/tcc.upp file is missing
* in tcc/libtcc.c the path must be /plugin/tcc/tcc.c
* a dependency on plugin/tcc must be added to package tcc

[Updated on: Wed, 12 October 2011 22:58]

Report message to a moderator

Re: TCC package broken [message #34039 is a reply to message #34038] Thu, 13 October 2011 09:09 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
Hello Didier

Thank you. I probably lost some changes. Last months I have changed PCs and I have had problems losing things Rolling Eyes.

About plugin/tcc package... in fact it did not existed before Smile.

However it is better this way. I did Tcc package when I had less knowledge of U++ Rolling Eyes . plugin/tcc/tcc.upp is now created and added to Tcc. Of course old libtcc.c file has been removed.

It will be updated this afternoon.



Best regards
Iñaki
Re: TCC package broken [message #34046 is a reply to message #34039] Thu, 13 October 2011 20:02 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 740
Registered: November 2008
Location: France
Contributor
Thank's Koldo

Re: TCC package broken [message #34052 is a reply to message #34046] Thu, 13 October 2011 21:43 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
Thank you. It is updated yet. Please check it. Smile

Best regards
Iñaki
Re: TCC package broken [message #34106 is a reply to message #34052] Tue, 18 October 2011 22:55 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 740
Registered: November 2008
Location: France
Contributor
Hi Koldo,

I tried you're modifications and all works fine under linux.

Thank's for the corrections
Re: TCC package broken [message #34111 is a reply to message #34106] Wed, 19 October 2011 13:44 Go to previous message
koldo is currently offline  koldo
Messages: 3458
Registered: August 2008
Senior Veteran
Great! Smile

Best regards
Iñaki
Previous Topic: Scatter: To find width bwt any two points.
Next Topic: User configurable menu system
Goto Forum:
  


Current Time: Mon Apr 27 22:01:37 GMT+2 2026

Total time taken to generate the page: 0.01260 seconds