LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-06-2006, 11:53 AM   #1
cjbrockwell
LQ Newbie
 
Registered: Sep 2006
Posts: 1

Rep: Reputation: 0
undefined reference to main


Hi People,

I'm getting the following error from ld (via g++ -z)

/usr/lib/gcc-lib/i386-redhat-linux/3.2.3/../../../crt1.o(.text+0x18): In function `_start':
: undefined reference to `main'

I'm at my wits end.
In anticipation of likely responses .....

1. Yes, I have defined main ... like so
int main (int argc, char * argv [])

2. It's been built - I can see the main.o

3. The link command does include the object file ...
(linker command pasted below this message)

can anyone help / make any suggestion.

I'm currently reduced to playing with the ordering of the .o's in the makefile and have the distinct feeling I'm wasting my (employers) time.

Many thanks.

Chris







g++ -z ./main.o ./smarttest_commands.o ./command_createconn.o ./command_connect.o ./command_createevent.o ./command_createmt.o ./command_destroyconn.o ./command_destroyevent.o ./command_disconnect.o ./command_namespace.o ./command_on.o ./command_ping.o ./command_publish.o ./command_reportlatencies.o ./command_reschedule.o ./command_resetlatencies.o ./command_send.o ./command_setrate.o ./command_sleep.o ./command_subscribe.o ./namespace.o ./parse.o ./ping.o ./rates.o ./smarttest_mt.o ./outgoingmessagetracker.o ./reportmissingmsgsevent.o ./smarttest_environment.o ./latency_cb.o ./incomingmessagetracker.o ./MWInterface.o ./SSInterface.o ./MWSpecificOptions.o ./command.o ./rngs.o ./rvgs.o -L../SSUtils/ -L/apps/smartsockets/smarttestdev/ss6703sc112br113/lib/i86_linux/static -L/usr/lib/gcc-lib/i386-redhat-linux/3.2.3/ -lssutils -lrtsscpp50 -lrtipc -lrtmsg -lrtsubj -lrtconn -lrtipcl -lrtedm -lrtutil -lrtsm -lnsl -lpthread -ldl -lm -lrt -lc -lstdc++ -o smarttest.x
/usr/lib/gcc-lib/i386-redhat-linux/3.2.3/../../../crt1.o(.text+0x18): In function `_start':
: undefined reference to `main'
collect2: ld returned 1 exit status
gmake: *** [smarttest.x] Error 1
 
Old 09-06-2006, 03:05 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,983
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Hi,

and welcome to LQ!

Is that actually C++ code, or C?
If it's the latter, try using gcc instead of g++



Cheers,
Tink
 
Old 09-06-2006, 03:22 PM   #3
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,537

Rep: Reputation: 149Reputation: 149
And if you prefer to stay with g++ make sure you have
Code:
using namespace std;
 
Old 09-06-2006, 05:09 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
The '-z' option expects an argument; it's using 'main.o' as that argument, and that file isn't getting linked.
ta0kira
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting undefined reference to main error?? Mistro116@yahoo.com Programming 14 07-29-2011 08:28 AM
Undefined reference, why? george_mercury Programming 4 05-07-2009 12:15 AM
undefined reference vkmgeek Programming 1 05-11-2006 06:37 AM
undefined reference mp4-10 Programming 3 01-25-2005 12:38 PM
emacs 77: undefined reference to `main' creznedmick Programming 2 09-16-2003 07:46 PM


All times are GMT -5. The time now is 09:37 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration