[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 673
  • Last Modified:

What's wrong with my makefile?

Hi experts,

I am trying to compile some codes, and the following is the makefile:
--------------------------------------
all: waveletTrans.exe

waveletTrans.exe: main.o wt1.o daub4.o pwt.o pwtset.o
        g++ -O3 main.o wt1.o daub4.o pwt.o pwtset.o -o waveletTrans.exe -lm

main.o: main.cpp
        g++ -c main.cpp

nrutil.o: nrutil.c nrutil.h
        g++ -c nrutil.c

wt1.o: wt1.c
        g++ -c wt1.c

daub4.o: daub4.c
        g++ -c daub4.c

pwt.o: pwt.c
        g++ -c pwt.c

pwtset.o: pwtset.c
        g++ -c pwtset.c

daub4.o pwt.o pwtset.o: nrutil.h

clean:
        rm -rf *o waveletTrans.exe
-----------------------------------------------
when I "make" it, I got the following errors:

g++ -c main.cpp
g++ -c wt1.c
g++ -c daub4.c
g++ -c pwt.c
g++ -c pwtset.c
g++ -O3 main.o wt1.o daub4.o pwt.o pwtset.o -o waveletTrans.exe -lm
daub4.o(.text+0x29): In function `daub4(float*, unsigned long, int)':
: undefined reference to `vector(long, long)'
daub4.o(.text+0x651): In function `daub4(float*, unsigned long, int)':
: undefined reference to `free_vector(float*, long, long)'
pwt.o(.text+0x29): In function `pwt(float*, unsigned long, int)':
: undefined reference to `vector(long, long)'
pwt.o(.text+0x3d8): In function `pwt(float*, unsigned long, int)':
: undefined reference to `free_vector(float*, long, long)'
pwtset.o(.text+0x7c): In function `pwtset(int)':
: undefined reference to `nrerror(char*)'
collect2: ld returned 1 exit status
make: *** [waveletTrans.exe] Error 1

---------------------------------------------
Does anyone know what I did wrong in the make file? (nrutil, daub4, wt1, pwt and pwtset are standard numerical recipes subroutines)

Thanks very much!
0
meow00
Asked:
meow00
  • 2
1 Solution
 
Infinity08Commented:
Where are vector, free_vector and nrerror defined ?
0
 
meow00Author Commented:
They are in the nrutil.h and nrutil.c, and I put all these files in the same directory.
0
 
Infinity08Commented:
You forgot the nrutil.o file in the link step :

waveletTrans.exe: main.o wt1.o daub4.o pwt.o pwtset.o
        g++ -O3 main.o wt1.o daub4.o pwt.o pwtset.o -o waveletTrans.exe -lm

should be :

waveletTrans.exe: main.o nrutil.o wt1.o daub4.o pwt.o pwtset.o
        g++ -O3 main.o nrutil.o wt1.o daub4.o pwt.o pwtset.o -o waveletTrans.exe -lm
0
 
evilrixSenior Software Engineer (Avast)Commented:
Also, the order you link is important, you list dependers before dependees. So, if A depends on B you must link to A before B so that the linker knows what symbols to pull our of B for A.

It's counter intuitive and catches out a lot of noob g++ers :)

-Rx.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now