Jump to content

Ability to compile a C/++ executable on a...


JohnOne
 Share

Recommended Posts

... machine which has not IDE or compiler installed.

Goal:

An end user can input some data, for instance a number of file names.

An executable is compiled which when ran opened all of those files.

What would I need to distribute in a package if I wanted to be able to do that.

Free compiler, libraries etc?

I'm talking the bare minimum tools and utilities I would need.

Appreciate any advice, and the filenames and opening is just an example it could be the end exe draws a line or does a calculation etc.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I'm rather lousy at explaining stuff so here is an example of what I mean.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$GUI = GUICreate("GUI", 229, 184, 192, 124)
$Label = GUICtrlCreateLabel("What do you want", 40, 40, 91, 17)
$Combo = GUICtrlCreateCombo("Select", 40, 72, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData($Combo, "Open a file|Something else")
$Button = GUICtrlCreateButton("Ok", 40, 112, 75, 25)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            Switch GUICtrlRead($Combo)
                Case "Open a file"
                    _OpenAFile()
                Case "Something else"
                    _SomethingElse()
                Case Else
                    _ErrorFunc()

            EndSwitch
    EndSwitch
WEnd

Func _OpenAFile()
    ConsoleWrite("//Open file" & @LF)
    ;Create the cpp file.
    $sFile = '#include <windows.h>' & @LF
    $sFile &= '#include <ShellApi.h>' & @LF
    $sFile &= @LF
    $sFile &= 'int main()' & @LF
    $sFile &= '{' & @LF
    $sFile &= 'ShellExecute(NULL, L"open", L"C:\\File.txt", NULL, NULL, SW_SHOW);' & @LF
    $sFile &= @LF
    $sFile &= 'return 0;' & @LF
    $sFile &= '}' & @LF
    ConsoleWrite($sFile & @LF)
    ;FileWrite("name.cpp", $sFile)
    
    ; Now compile this to exe. 
    
EndFunc

Func _SomethingElse()
    ConsoleWrite("Something else" & @LF)
EndFunc

Func _ErrorFunc()
    ConsoleWrite("Error" & @LF)
EndFunc

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Then tcc is the way to go. It compiles and links almost as fast as simply loading an exe from disk. Give it a try to experience what I mean.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

I will do, have to look into it first. Never compiled from command line or anything before see.

Speed is not an issue. the created binary will not be ran on the fly, but for future use.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

@Mat and @jchd:

I've always used MinGW for these types of tasks, mostly because it's already on my computer anyway for Perl's CPAN.

TCC looks awesome and I'd never heard of it.  I know I'm not the one that asked the question - but thanks for the pointer nonetheless!

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Link to comment
Share on other sites

tcc and gcc don't live on the same planet, not even in the same galaxy. Of course gcc is much more powerful and comes with state of the art optimizations and cross-compile possibilities. It would be naïve to expect a 1.5Mb compiler+linker+libraries+doc+examples to be able to compete with VS or gcc or Intel or some other monster toolchain. Yet tcc is surprisingly tiny, fast and good at what it aims to do.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Good point - and I'll keep that in mind.  But the little bit of hand-written C code I currently compile in MinGW would probably work just fine in TCC.

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Link to comment
Share on other sites

After looking at your example AutoIt code, I can see you importing some headers. You'll need to have those headers available (along with all headers they depend on, plus lib files when appropriate) with your compiler.

That's why compilers tend to be in a Software Development Kit (SDK) rather than a standalone executable.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...