Jump to page: 1 2 3
Thread overview
[Issue 9723] New: add missing main() when compiling exe with -unittest
Mar 14, 2013
Walter Bright
Mar 14, 2013
Andrej Mitrovic
Mar 14, 2013
Walter Bright
Mar 15, 2013
Andrej Mitrovic
Mar 15, 2013
Andrej Mitrovic
Mar 15, 2013
Walter Bright
Mar 15, 2013
Vladimir Panteleev
Mar 15, 2013
Vladimir Panteleev
Mar 15, 2013
Walter Bright
Mar 15, 2013
Walter Bright
Mar 15, 2013
Vladimir Panteleev
Mar 15, 2013
Walter Bright
Mar 15, 2013
Andrej Mitrovic
Mar 15, 2013
Andrej Mitrovic
Mar 16, 2013
Andrej Mitrovic
Mar 16, 2013
Andrej Mitrovic
Mar 16, 2013
Walter Bright
Mar 16, 2013
Andrej Mitrovic
[Issue 9723] Implement -main switch to inject a default main() function
Apr 12, 2013
Andrej Mitrovic
March 14, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9723

           Summary: add missing main() when compiling exe with -unittest
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: bugzilla@digitalmars.com


--- Comment #0 from Walter Bright <bugzilla@digitalmars.com> 2013-03-14 14:32:08 PDT ---
When compiling a module with -unittest, and an exe file is being generated, and there is no main() function, add:

   int main() { return 0; }

and compile it in.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 14, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9723


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-14 14:55:25 PDT ---
How can you reasonably implement this if you pass object files or static libraries to DMD which might contain main? E.g.:

foo.d:
import bar;
void main()
{
}

bar.d:
unittest
{
    assert(0);
}

$ dmd -c foo.d
$ dmd -unittest -ofbar.exe foo.d bar.obj

You could end up getting linker errors if DMD tries to add another main function.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 14, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9723



--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2013-03-14 16:59:40 PDT ---
Good point. You can deal with it by not doing it if there are any explicit .o files on the command line. No need to worry about libraries with main() in it - nothing to pull it in.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9723



--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-14 17:02:11 PDT ---
(In reply to comment #2)
> No need to worry about libraries with main() in it -
> nothing to pull it in.

What do you mean by that?

Also we have --main in RDMD that is used exactly for this purpose. Why not just move this switch over to DMD instead of doing magic that stops working as soon as you add separately-compiled dependencies?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9723



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-14 17:03:12 PDT ---
(In reply to comment #3)
> (In reply to comment #2)
> > No need to worry about libraries with main() in it -
> > nothing to pull it in.
> 
> What do you mean by that?
> 
> Also we have --main in RDMD that is used exactly for this purpose. Why not just move this switch over to DMD instead of doing magic that stops working as soon as you add separately-compiled dependencies?

Also, by doing it as a switch we can keep compatibility with RDMD, all it has to do is call DMD's -main switch instead of making a separate file with main in it. So old code continues to work.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9723



--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> 2013-03-14 17:39:32 PDT ---
I mean that if you've installed main() in a library file, it won't get pulled in unless you have a reference to main somewhere else, which is awfully unlikely and I've never seen it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9723


Vladimir Panteleev <thecybershadow@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow@gmail.com


--- Comment #6 from Vladimir Panteleev <thecybershadow@gmail.com> 2013-03-15 02:49:04 EET ---
Some libraries define main(), and let the user define their own entry point.
E.g. libfoo could have a foomain() declaration, and the user has to implement
it.

I believe SDL is one library that does this.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9723



--- Comment #7 from Vladimir Panteleev <thecybershadow@gmail.com> 2013-03-15 02:50:13 EET ---
(In reply to comment #5)
> I mean that if you've installed main() in a library file, it won't get pulled in unless you have a reference to main somewhere else, which is awfully unlikely and I've never seen it.

Doesn't the C runtime have a reference to main()?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9723



--- Comment #8 from Walter Bright <bugzilla@digitalmars.com> 2013-03-14 18:01:12 PDT ---
(In reply to comment #7)
> Doesn't the C runtime have a reference to main()?

No.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9723



--- Comment #9 from Walter Bright <bugzilla@digitalmars.com> 2013-03-14 18:04:34 PDT ---
(In reply to comment #6)
> Some libraries define main(), and let the user define their own entry point.

Even if there are some, the workaround is pretty easy - just add a module, any module, in .o form to the command line.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2 3