Undefined reference problem when compiling smile

The engine.
Post Reply
mepster
Posts: 3
Joined: Thu Jul 17, 2008 4:35 pm

Undefined reference problem when compiling smile

Post by mepster »

Hello

I am new to smile and am trying to compile a very basic peice of code as a start. I am running Gentoo Linux on 64bit machine, using gcc version 4.3.1. I have downloaded smile_1_1_linux64_gcc_4_1_2.tar.gz and am using those header files in a sub directory. When I try and compile my code I get an undefined reference error:

main.cpp:(.text+0x7b): undefined reference to`DSL_dataset::DSL_dataset()'
collect2: ld returned 1 exit status

Makefile
============
SMILE = /home/me/Desktop/Smile\ trial/Smile_Headers
CFLAGS=-I/usr/X11R6/include -DEDEBUG -ffast-math
LDFLAGS=-L/usr/X11R6/lib

pc: main.o
g++ -g $(LDFLAGS) $(SMILE)/libsmilearn.a -o pc main.o

main.o: main.cpp
g++ $(CFLAGS) -c main.cpp -w

============
main.cpp
============
#include <iostream>
#include "Smile_Headers/smilearn.h"

using namespace std;

int main (int argc, char *argv[]){
DSL_variableInfo vi;
DSL_dataset ds;
}
============

Please could you help me with this problem.
Thanks.
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: Undefined reference problem when compiling smile

Post by shooltz[BayesFusion] »

You have a space in $(SMILE) - it's between 'Smile\' and 'trial'.
mepster
Posts: 3
Joined: Thu Jul 17, 2008 4:35 pm

Post by mepster »

Thanks for the reply, though I am still stuck with the error. I have replaced the space with an underscore now:
SMILE = /home/me/Desktop/Smile_trial/Smile_Headers

However I still get the same error. I also tried commenting out the "DSL_dataset ds;" after which the code then compiled correctly. I don't know if there was a form of instillation (./configure?) that I maybe missed.

Thanks
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Post by shooltz[BayesFusion] »

mepster wrote:However I still get the same error. I also tried commenting out the "DSL_dataset ds;" after which the code then compiled correctly. I don't know if there was a form of instillation (./configure?) that I maybe missed.
There's no install/setup - unpacking the files is enough.

What happens if you invoke gcc directly, like this? xxx is the location of libsmilearn.a and libsmile.a.

g++ main.cpp -Lxxx -lsmilearn -lsmile
mepster
Posts: 3
Joined: Thu Jul 17, 2008 4:35 pm

Post by mepster »

That worked. Thanks. It turns out the main.o was at the end of the line when it actually should have been at the begining. So my final makefile is:

============================
SMILE = /home/me/Desktop/Smile_trial/Smile_Headers
CFLAGS= -I/usr/X11R6/include -DEDEBUG -ffast-math
LDFLAGS= -L$(SMILE) -lsmilearn -lsmile

pc: main.o
g++ main.o $(LDFLAGS) -o pc

main.o: main.cpp
g++ $(CFLAGS) -c main.cpp -w
============================

Thanks for the help.
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Post by shooltz[BayesFusion] »

Note that SMILE is actually build with -DNDEBUG, not -DEDEBUG.
Post Reply