By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Changing entry point function

P: n/a
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 ?

Aug 8 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Aug 8, 3:26 pm, Premkumar <contactp...@gmail.comwrote:
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).

Aug 8 '07 #2

P: n/a
Premkumar 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 ?
Mistake: posting to the wrong newsgroup. Your question is about G++,
so ask it in the G++ newsgroup: gnu.g++.help.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 8 '07 #3

P: n/a
jg
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
You may provide a dummy main and try the above again.
Why do you want to use different entry rather than main ?
Just curious.

JG

Aug 9 '07 #4

P: n/a
We have a set of test modules which are derived from a specific base
class . All the .cpp files have their own main functions.
I'm writing a small module to automate all these classes.
I just want to implement it in a way that affects the existing modules
to the least.

I wanted the new main(from my class) function to be called when the
automation is executed ..
I got away of the different main functions by using the --allow-
multiple-definitions flag of the linker.

I understand the design of the other classes can be changed to achieve
this, but the org wont allow this.


On Aug 8, 10:24 pm, jg <jgu...@gmail.comwrote:
g++ -Wl,-emymain__Fv a.o
Now the linker says:
/usr/lib/crt1.o(.text+0x18): Infunction`_start':
: undefined reference to `main'
collect2: ld returned 1 exit status

You may provide a dummy main and try the above again.
Why do you want to use differententryrather than main ?
Just curious.

JG

Aug 9 '07 #5

P: n/a
Premk wrote:
We have a set of test modules which are derived from a specific base
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.com/c++-faq-lite/how-to-post.html>
Aug 9 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.