LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 09-06-2006, 11:53 AM   #1
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.


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
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,041
Blog Entries: 11

Rep: Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907

and welcome to LQ!

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

Old 09-06-2006, 03:22 PM   #3
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,545

Rep: Reputation: 160Reputation: 160
And if you prefer to stay with g++ make sure you have
using namespace std;
Old 09-06-2006, 05:09 PM   #4
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.


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?? 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 03:15 PM.

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