including libraries in Makefile.am


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting including libraries in Makefile.am
# 1  
Old 06-13-2011
including libraries in Makefile.am

hi,
I have the following code in my Makefile.am that works fine for simple programs:
Code:
bin_PROGRAMS=test
test_SOURCES=test.cpp

so, when I run 'make test', it runs the following command:
Code:
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:
Code:
g++ -o test test.cpp -L/usr/lib -lQuantLib

so, I modified my Makefile.am to include the following:
Code:
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

thanks!

Last edited by pludi; 06-13-2011 at 05:29 PM..
# 2  
Old 06-13-2011
-lQuantLib tells the linker to link the file libQuantLib.a, that is a static library, not a dynamic one (shared object) .so, which, being a dynamic
lib, would get loaded at runtime. Just specify the -lQuantLib in the rule:
Code:
LDFLAGS += -L/usr/lib
test_LDADD = -lQuantLib
bin_PROGRAMS:
         ${CXX} ${CXXFLAGS} ${LDFLAGS} -o $@ ${test_SOURCES} ${test_LDADD}

should do the trick, although /usr/lib should be in the default path to check for libs, and shouldn't need to be explicitly defined.
Obviously, file libQuantLib.a needs to be present in /usr/lib.
# 3  
Old 06-13-2011
hi mirni, thx. for your response.
I edited my Makefile with that code, but it still gives me the undefined reference errors.
Makefile.am
Code:
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:
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??
# 4  
Old 06-14-2011
Code:
LDFLAGS += -L/usr/lib

The plus and equal need to be together, it's one operator, just like in C.
To debug Makefile, you should look at the command that's executed when you run 'make'. The command that's being run is echoed on stdout. Look carefully at that command -- it should be exactly what you want:
Code:
g++ -L/usr/lib -o test test.cpp -lQuantLib

Since you are getting the errors, you will see something else:
it'll be missing either the -L/usr/lib or -lQuantLib.

Also, just to be safe, delete the old object file test.o before recompiling.
# 5  
Old 06-14-2011
hi mirni,
thanks for the correction.
I was getting an error message with LD_FLAGS, wherein automake warned me to use AM_LDFLAGS since LD_FLAGS is a user defined variable. then I got warned to use = for AM_LDFLAGS before using +=, so I rewrote Makefile.am as:
Code:
AM_LDFLAGS = -L/usr/lib
bin_PROGRAMS = test
test_SOURCES=test.cpp
test_LDADD = -lQuantLib
bin_PROGRAMS:
    ${CXX} ${CXXFLAGS} ${AM_LDFLAGS} -o $@ ${test_SOURCES} ${test_LDADD}

and when I run make test,
this is what it shows:
Code:
g++ -c -o test.o test.cpp

I deleted the old test.o file, and re-ran 'make test'
Code:
g++ test.cpp -o test

so, obviously it is not reading the -L or -l flags....any thoughts
why and how I can fix it...
# 6  
Old 06-14-2011
Sorry bacpp, I mistakenly thought you were writing a Makefile and using GNU make. My advice was for that case.
Usage of GNU automake and Makefile.am is different, and I don't have experience with writing Makefile.am myself, but from automake it seems that all you need is:
Code:
test_LDADD = /usr/lib/libQuantLib.a

# 7  
Old 06-14-2011
thanks mirni, but it still ain't working Smilie....I think I will go and study the Libtool and try it again Smilie....if it works, I'll post the code here.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Help with Simple Multi-Level Makefile (Extremely New at Makefile)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Basically, the prompt is make a makefile with various sub makefiles in their respective subdirectories. All code... (1 Reply)
Discussion started by: Tatl
1 Replies

2. UNIX for Advanced & Expert Users

Makefile executing another Makefile first?

I have 2 libraries in 2 different directories that I build with Makefiles. library B depends on library A. If I modify a .cpp file in library A and run lib B's Makefile can I have B's makefile to automatically rebuild library A? I am now rebuilding A, followed by B... but I'd like B to... (0 Replies)
Discussion started by: wwuster
0 Replies

3. Programming

Error while including libraries

Hi All, When i am trying to include graphics.h ,dos.h and conio.h, its giving error as follows: pgm.c:2:17: dos.h: No such file or directory pgm.c:3:22: graphics.h: No such file or directory pgm.c:4:19: conio.h: No such file or directory Whereas stdio.h, stdlib.h and time.h gets... (3 Replies)
Discussion started by: jisha
3 Replies

4. Solaris

System Libraries used by makefile

Dear All I am looking for all the system libraries that are accessed by my application Build script i.e. make which in turn will processes makefile. Is there any specific command from which i can find all the system libraries used by my build script. Cheers, Ankur (1 Reply)
Discussion started by: sharmaankur85
1 Replies

5. UNIX for Advanced & Expert Users

Makefile problem - How to run module load in a Makefile

Hi, I'm trying to run the module load command in a Makefile and i'm getting the following error: make: module: command not found Why is this? Is there any way to run this command in a Makefile? NOTE: command - module load msjava/sunjdk/1.5.0 works fine outside of the Makefile (2 Replies)
Discussion started by: hernandinho
2 Replies

6. UNIX for Dummies Questions & Answers

Including files

Hi, Is it possible to include files (print with EOF, sort of like ssi) in perl/cgi? Thanks (1 Reply)
Discussion started by: marringi
1 Replies

7. Programming

Error different when including a printf

Hi I am trying to debug a code by including prinf . TO some extended it shows error at one point . If i include an extra printf it is showing at different point . Can anybody please let em know why it is happening .. Thaks, Arun (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

8. Shell Programming and Scripting

including a library file ?????

Whats the syntax for including a library file in a shell script? say my shell script name is <abc.sh> and my library file is present in /user/abc/hello/fsfs/fsfsss/library.lib Please tell how to include this library file in the shell script????? (6 Replies)
Discussion started by: skyineyes
6 Replies

9. Shell Programming and Scripting

PERL: including files

I am wondering how I can include external files in a perl script. I'm currently working on a website, and I'd like to put my menu items in a subroutine for example, and put that in another file such as menu.pl. That way, I can call the subroutine from each page (such as news.pl), and if I want to... (2 Replies)
Discussion started by: LNC
2 Replies

10. Programming

makefile for programs using libraries loaded at runtime

Hi everybody! I would like to set in the makefile a path that should be the path where the program searches for the libraries loaded at run time. Is there such a variable to be set in makefile? Thanks in advance! (1 Reply)
Discussion started by: nadiamihu
1 Replies
Login or Register to Ask a Question