Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm new in Ubuntu and trying to compile a C++ code on it. The code uses 2 dependencies (Cairographics and FFTW3). I have installed both of them using ./configure, make and make install in directory $HOME/prefix/ (following the instruction given here How to install Cairo 1.8.10 )

Now I have in this directory 4 folders, namely bin, include, lib and share

The make file of the code requires specifying the dependencies' directory. Like that

INC := -I$HOME/prefic/include
LIB := -L$HOME/prefic/lib

When I compile the code, I set the environment variables as

export PKG_CONFIG_PATH=$HOME/prefic/lib/pkgconfig
export LD_LIBRARY_PATH=$HOME/prefic/lib

and then use make. Linker gives "undefined reference to" functions from inside Cairo or FFTW

the make file I use

###################### user-configuration section #######################
INC := -I/opt/local/include
LIB := -L/opt/local/lib

# 32 bit
#MARCH := -m32

# 64 bit
MARCH := -m64
#########################################################################

CXX := g++
CXXFLAGS := -Wall -fopenmp
OPTFLAGS := -O3 $(MARCH) 

LIB += -lfftw3 -lm -lcairo

CXXFILES := main.cpp fileio.cpp measurements.cpp spectralanalysis.cpp
OBJS := $(patsubst %.cpp, %.o, $(CXXFILES))
TARGET := psa

.PHONY: all clean cleanall rebuild

 all: $(TARGET)

  $(TARGET): $(OBJS)
    @$(CXX) $(CXXFLAGS) $(OPTFLAGS) -o $(TARGET) $(LIB) $(OBJS)

 %.o : %.cpp
    @$(CXX) $(CXXFLAGS) $(OPTFLAGS) $(INC) -o $@ -c $<

 clean:
    rm -rf *.o

  cleanall:     clean
    rm -rf $(TARGET)

 rebuild:
     $(MAKE) cleanall
     $(MAKE) all

I think I don't link the code with the dependencies correctly. Could someone help please.

The psa code I'm trying to compile is here http://code.google.com/p/psa/downloads/list

share|improve this question
    
use gnu c++ complier –  BigSack Aug 18 '12 at 9:42
    
as I'm new for Ubuntu, Could you please tell me what is the difference between what I'm using and gun c++!! –  Ahmed Hassen Aug 18 '12 at 12:50
    
Do you know about CodeBlocks? or Eclipse? –  BigSack Aug 18 '12 at 16:07
add comment

1 Answer

up vote 0 down vote accepted

I think you need to move the libraries to the end of the command line (in your Makefile: place $(LIB) after $(OBJS)). The linker flag --as-needed is activated by default since Ubuntu 11.10. This makes the linker sensitive to the ordering of libraries on the command-line.

By the way: I don't know if you already know that, but you don't need to install Cairo and FFTW3 from source.

You can install the dependencies with the package management system:

sudo apt-get install libcairo2-dev libfftw3-dev

Then you have to change the following two lines in the Makefile:

INC := -I/usr/include
LIB := -L/usr/lib
share|improve this answer
    
It did work. Thanks a lot. –  Ahmed Hassen Aug 18 '12 at 12:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.