including libraries

hi,

I have the following code in my Makefile.am that works fine for simple programs:

bin_PROGRAMS=test
test_SOURCES=test.cpp

so, when I run 'make test', it runs the following command:
g++ -o test test.cpp

however, when I tried to run a program that includes the QuantLib library, I have to give the following command:
g++ -o test test.cpp -L/usr/lib -lQuantLib

so, I modified my Makefile.am to include the following:
test_LDADD = /usr/lib/libQuantLib.so

but that doesn't work; it gives me the same bunch of errors as it does if I only ran my test program without the -L and -l flags.

Can you please help me fix my Makefile.am code

thanks!
Could you please post the entire content of your makefile along with the compile errors you get?
hi Estee,

please find below the code for the makefile, and the linking errors....thanks!

Makefile.am

Code:
1
2
3
4
5
6
LDFLAGS+ = -L/usr/lib
bin_PROGRAMS = test
test_SOURCES=test.cpp
test_LDADD = -lQuantLib
bin_PROGRAMS:
    ${CXX} ${CXXFLAGS} ${LDFLAGS} -o $@ ${test_SOURCES} ${test_LDADD}


here's a sample of the errors:

Code:
1
2
3
4
5
6
test.o:(.rodata._ZTIN8QuantLib13TermStructureE[typeinfo for QuantLib::TermStructure]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
test.o:(.rodata._ZTIN8QuantLib12ExtrapolatorE[typeinfo for QuantLib::Extrapolator]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
test.o:(.rodata._ZTIN8QuantLib19StochasticProcess1D14discretizationE[typeinfo for QuantLib::StochasticProcess1D::discretization]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
test.o:(.rodata._ZTIN8QuantLib17StochasticProcess14discretizationE[typeinfo for QuantLib::StochasticProcess::discretization]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
test.o:(.rodata._ZTIN8QuantLib5QuoteE[typeinfo for QuantLib::Quote]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
test.o:(.rodata._ZTIN8QuantLib7VisitorINS_6PayoffEEE[typeinfo for QuantLib::Visitor<QuantLib::Payoff>]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'


when at the $ prompt, I give the following command:
 
g++ -o test test.cpp -L/usr/lib -lQuantLib

it works perfectly fine....I believe it is a linking error
Hi bacpp

I'm not at all an expert on makefiles, but I think maybe the problem is the order in which you pass arguments to g++. I'm not sure though. but try this: (be careful with copy-paste as the indention is off)

1
2
3
4
SOURCE = test.cpp
LIBS   = -L/usr/lib -lQuantLib
test:
    ${CXX} ${CXXFLAGS} -o $@ ${SOURCE} ${LIBS}


This makefile produces the following:
1
2
 	
g++ -o test test.cpp -L/usr/lib -lQuantLib


The makefile you posted produced:
 
g++ -L/usr/lib -o bin_PROGRAMS test.cpp -lQuantLib


Remember that here:
1
2
bin_PROGRAMS:
    ${CXX} ${CXXFLAGS} ${LDFLAGS} -o $@ ${test_SOURCES} ${test_LDADD}

bin_PROGRAMS does not refer to ${bin_PROGRAMS}, so your output will be an executable named bin_PROGRAM. You are actually not using the ${bin_PROGRAMS} variable. When you refer to $@ you refer to the target:

1
2
bin_PROGRAMS: <-Target
    ${CXX} ${CXXFLAGS} ${LDFLAGS} -o $@ ${test_SOURCES} ${test_LDAD}


I have the lib path and name in the same variable, and this is a matter of taste and therefore completely optional.

Hope it worked.
hi Estee,
thanks for the correction...

so I did the following:
1
2
3
4
SOURCE = test.cpp
LIBS   = -L/usr/lib -lQuantLib
test:
	 ${CXX} ${CXXFLAGS} -o $@ ${SOURCE} ${LIBS}


when i run make test, it returns:
 
g++ test.cpp -o test


why would it not be reading ${LIBS}.....
Ahh, it seems I did not read your first post thoroughly enough. :-)

What you need to do is:
Rename MakeFile.am to MakeFile and try it again.

When you run
 
make test

the Make utility looks for a file named MakeFile. It does not look for a MakeFile.am. MakeFile.am is a file generated by automake. So in your case, it does not find a Makefile and it just do a standard compilation of test.cpp
An easy way to test this is to issue
 
make

instead of
 
make [target]

The latter command is only used if you have more than one MakeFile in your working directory.

Hope this did the trick ;-)
Last edited on
aha, it worked like a charm....thanks Estee...I used the following code and renamed the file...and then issued make
1
2
3
4
5
6
AM_LDFLAGS = -L/usr/lib
bin_PROGRAMS = test
_SOURCES = test.cpp
_LDADD = -lQuantLib
${bin_PROGRAMS}:
	${CXX} ${CXXFLAGS} -o $@ ${_SOURCES} ${AM_LDFLAGS} ${_LDADD}

thx very much!
Last edited on
No problem :-)
Topic archived. No new replies allowed.