LinuxQuestions.org
Review your favorite Linux distribution.
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
 
LinkBack Search this Thread
Old 07-04-2007, 06:58 AM   #1
myhanguk
LQ Newbie
 
Registered: Jun 2007
Posts: 5

Rep: Reputation: 0
Undefined reference to 'main'


SORRY: THE HEADLINE IS WRONG... I resolved the undefined reference to main error but still
cannot get my Makefile to work...

I get some weird undefined reference errors:
In function 'main':
wlan/include/wlan_modem.h: undefined reference to 'cWlan:PLCP::TXSTART_req(...)'
although wlan_modem.h does not make any call to this function ??? More info below, in my
firt posting:

-------------------------------------------------------------------------------------------
Hi... I've been stuck the whole day trying to build this @#%$@$!! program on linux (I am a VC++ user..., works fine there). Can anyone help me out? I'm cannot afford to lose more time one this....

My test program is called wlan_test.cpp and this is the one I need to make
an executable for.

My Makefile without the compilation and linking steps looks as follows:

INCLUDE = /user/niko/NP_NEW/extern/include
LIBS = /user/niko/NP_NEW/extern/lib #I am using libfftw3.h libgsl.a and
#libgslcblas.a here

.SUFFIXES = .cpp .o
CPP = g++
CPPFLAGS = -g -c
TOP_OBJ = wlan_test.o
PHY_OBJ = wlan/source/wlan_cpi.o\
etc...

CHN_OBJ = channel/source/channel.o\
etc...

LIB_OBJ = library/source/binary.o\
etc...


TOP_SRC = $(TOP_OBJ:.o=.cpp)
PHY_SRC = $(PHY_OBJ:.o=.cpp)
CHN_SRC = $(CHN_OBJ:.o=.cpp)
LIB_SRC = $(LIB_OBJ:.o=.cpp)
SRC = $(TOP_SRC) $(PHY_SRC) $(CHN_SRC) $(LIB_SRC)

#QUESTION:
#WHAT SHOULD I PUT HERE TO GET TO BUILD THE EXECUTABLE FILE
#wlan_test to be build? (including the -I and -L options for my include path
#and library path (fftw and gsl - header files in #directory /user/niko/extern/include and .a files in extern/lib
#I tried many things but they always give me some error of undefined #reference to the library functions, or even to 'main', etc...
#thanks for your help!

clean :
rm -f $(TOP_OBJ) $(PHY_OBJ) $(CHN_OBJ) $(LIB_OBJ)

dep :
gccmakedep $(INCLUDE) $(SRC)

#below the dependencies as generated by 'make dep' above

# DO NOT DELETE
wlan_test.o: wlan_test.cpp ....
etc...



How can I successfully compile and link the whole stuff? I tried (amongst others) using

tmp : $(TOP_OBJ) $(PHY_OBJ) $(CHN_OBJ) $(LIB_OBJ)
$(CPP) -I$(INCLUDE) -L$(LIBS) -o $@ $(TOP_OBJ) $(PHY_OBJ) $(CHN_OBJ) $(LIB_OBJ) -lfftw3 -lgsl -lgslcblas

but I get some weird undefined reference errors:
In function 'main':
wlan/include/wlan_modem.h: undefined reference to 'cWlan:PLCP::TXSTART_req(...)'
although wlan_modem.h does not make any call to this function ???

Thanks for you input on this !!!

Niko

Last edited by myhanguk; 07-05-2007 at 03:33 AM.
 
Old 07-04-2007, 07:36 AM   #2
UndiFineD
LQ Newbie
 
Registered: Jun 2004
Location: Netherlands
Distribution: adistro
Posts: 21

Rep: Reputation: 0
-> main
 
Old 07-04-2007, 03:51 PM   #3
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,408

Rep: Reputation: 108Reputation: 108
Make sure wlan_modem.h does not include any file that uses that undefined functions. It may be that you have two files of the same name: one in your project and one somewhere in the system libraries. If the wrong one is included, you may have such problem. Try the locate commands to search for files (especially includes) with conflicting names.

The tmp: line looks quite fine. I'd only put simply -o tmp_test instead of -o $@
 
Old 07-04-2007, 06:50 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: Slackware64 13.37, Kubuntu 10.04
Posts: 2,944

Rep: Reputation: Disabled
You probably need to -l a library associated with that include when you link. Even if the header doesn't call the function it's probably declared somewhere (that header or another it includes.) It's also possible that the library you're linking to leaves it undefined so that another library will define it, or maybe it expects the final program to define it.
ta0kira
 
Old 07-05-2007, 02:16 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Puppy
Posts: 3,048

Rep: Reputation: 95
do you know the name of the library you are using?

look in /usr/lib /usr/local/lib and any other candidates for the library
it will look like libBlah.so or similar, then

export LD_FLAGS = -L /blah/blah/lib -lBlah
 
Old 07-05-2007, 03:32 AM   #6
myhanguk
LQ Newbie
 
Registered: Jun 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Dear All,
Many thanks for your reactions on this!
I finally got the thing to work (thanks to someone else's input) by writing the tmp line
as follows:

tmp : $(TOP_OBJ) $(PHY_OBJ) $(CHN_OBJ) $(LIB_OBJ)
$(CPP) -I$(INCLUDE) -L$(LIBS) $(TOP_OBJ) $(PHY_OBJ) $(CHN_OBJ) $(LIB_OBJ) -lfftw3 -lgsl -lgslcblas -o wlan.exe
i.e. by putting the -o wlan.exe at the end and not using the -o $@ as before...

Thanks again to all,

Niko

Last edited by myhanguk; 07-05-2007 at 03:35 AM.
 
  


Reply

Tags
make, makefile, reference, undefined


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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 to main () ?. rameshs Linux - Newbie 3 01-11-2007 06:29 PM
Gcj undefined reference main (hello world program) SW-ANIKY Programming 1 12-16-2006 10:08 AM
undefined reference to main cjbrockwell Programming 3 09-06-2006 05:09 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 05:40 AM.

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
Open Source Consulting | Domain Registration