2

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

  • use gnu c++ complier – BigSack Aug 18 '12 at 9:42
  • Do you know about CodeBlocks? or Eclipse? – BigSack Aug 18 '12 at 16:07
0

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
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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