LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Undefined reference to 'main' (http://www.linuxquestions.org/questions/programming-9/undefined-reference-to-main-566562/)

myhanguk 07-04-2007 06:58 AM

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

UndiFineD 07-04-2007 07:36 AM

-> main :p

Mara 07-04-2007 03:51 PM

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 $@

ta0kira 07-04-2007 06:50 PM

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

bigearsbilly 07-05-2007 02:16 AM

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

myhanguk 07-05-2007 03:32 AM

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


All times are GMT -5. The time now is 07:28 PM.