help-gplusplus
[Top][All Lists]
Advanced

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

Re: Changing entry point function


From: redfloyd
Subject: Re: Changing entry point function
Date: Wed, 08 Aug 2007 15:57:10 -0700
User-agent: G2/1.0

On Aug 8, 3:26 pm, Premkumar <contactp...@gmail.com> wrote:
> a.cpp
> ----------------------------------
> #include <iostream>
> using namespace std;
>
> void mymain() {
>         cout<<"my-main"<<endl;}
>
> ----------------------------------
>
> I'm trying to start my program at mymain than the standard main ..
> So I compiled a.cpp to a.o &
>
> I executed :
> g++ -Wl,-emymain  a.o
>
> That did not work as the linker said it could not find the symbol. So
> I used name mangler (nm) to demangle a.o
> g++ -Wl,-emymain__Fv  a.o
>
> Now the linker says:
> /usr/lib/crt1.o(.text+0x18): In function `_start':
> : undefined reference to `main'
> collect2: ld returned 1 exit status
>
> I also tried the following
> g++ -Wl,--verbose -Wl,-emymain__Fv -Wl,--defsym -Wl,start=mymain__Fv
> a.o
> g++ -Wl,--verbose -Wl,-emymain__Fv -Wl,--defsym -Wl,_start=mymain__Fv
> a.o
>
> Still no use..
>
> What mistake am I making here ?


Asking in the wrong group?  Changing the "entry" point is a g++
question.  I'd recommend asking in gnu.g++.help.

BEGIN OFF TOPIC
The entry point for a g++ program is not "main", but some other symbol
(probably "start"), which sets up the runtime environment and then
calls main.  So changing the entry point in the linker does nothing.
END OFF TOPIC

Per the standard "main" is the entry point once global variables and
the runtim library have been initialized.

If you really want mymain(), do the following:


void mymain()
{
}


int main()
{
   mymain();
}

Please note that main *must* return int (with an implicit 0 return).



reply via email to

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