473,396 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Changing entry point function

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
5 3939
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Laurent Schall | last post by:
I experience a problem where starting an application compiled with visual C++ 6 SP5 does not execute the function main(int argc, char **argv) and exit immediately with code 1 (0x1). Putting main...
1
by: Wayne | last post by:
I'm using the following code from the Access Web to open a folder. The folder opens in "List" View. Is there an addition that I can make to the code to force the folder to open in "Details" view?...
6
by: aneesh | last post by:
Hi all, I would like to know whether we can specify another function instead of main as entry point. Thanks Aneesh
14
by: Vijay Kumar R Zanvar | last post by:
I have following questions: 1. Appendix C of K&R says: Trigraph sequences introduced by ?? allow representation of characters lacking in some character sets. ... Can somebody explain how...
5
by: Mike in Santa Rosa | last post by:
I'm trying to get a simple c# app built that can launch/manipulate an excel workbook, sheet. I've chased down several examples and can't any of them to work. So I must be doing somethnig obviouslt...
8
by: Johnny | last post by:
Hi, Is there a way to detect the entry point of all the functions in a project? If so, can I make a function that will be called at the every entry point? Thanks for your consideration. ...
2
by: bboule | last post by:
Hi I have developped a dll that I want to use in another program ! here is my code : using System; using System.Collections.Generic; using System.Text; namespace NameSpace
10
by: Lung.S.wu | last post by:
Hi all, It is a history question. Recently, I read the book "C A reference manual, third edition". In this book, it list all C language keyword, and one is "entry". I know it is omitted from...
3
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I am a developer from C++ COM to C# COM. I feel confused about the entry point function for a C# COM object. In C++, we always initialize object through GetClassObject or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.