Sponsored Content
Full Discussion: Library linking with GMP
Top Forums Programming Library linking with GMP Post 302433181 by drl on Monday 28th of June 2010 11:02:27 PM
Old 06-29-2010
Hi.

I have no experience with gmp, and little with c++. However, I had been looking at ld today, and thought I would try a few things.

Briefly, I downloaded gmp 5.x from gnu.org, compiled it with your .configure line (into ~/gmp), ran make, make check, make install. Then I created a script, s1, to try the test code compile, link, execute. The (lengthy) results are below in 3 sections: my environment, the script, and the "link trace" compile, link, execute.
Code:
OS, ker|rel, machine: Linux, 2.6.26-2-686, i686
Distribution        : Debian GNU/Linux 5.0 
g++ (Debian 4.3.2-1.1) 4.3.2
GNU ld (GNU Binutils for Debian) 2.18.0.20080103

-----

#!/usr/bin/env bash

# g++ gmptest.cxx -I/Users/****/gmp/lib/ -I/Users/****/gmp/include/ -L/Users/****/gmp/lib/ -lgmpxx -lgmp -o gmptest

my_gmp=/home/drl/gmp
# g++ -t t1.cpp -I$my_gmp/lib -I$my_gmp/include -L$my_gmp/lib -lgmpxx -lgmp -o gmptest
# g++ -t t1.cpp -I$my_gmp/lib -I$my_gmp/include -L$my_gmp/lib -o gmptest
# g++ -t t1.cpp -I$my_gmp/lib -I$my_gmp/include "-Wl,-rpath $my_gmp/lib/" -o gmptest
# g++ -t t1.cpp -I$my_gmp/include "-Wl,-R $my_gmp/lib/" -o gmptest
# fails, g++ -t t1.cpp -I$my_gmp/include $my_gmp/lib/*.so -o gmptest
# works, g++ -t t1.cpp -I$my_gmp/include $my_gmp/lib/*.a -o gmptest
g++ -t t1.cpp -I$my_gmp/include $my_gmp/lib/*.a -o gmptest

./gmptest

-----

/usr/bin/ld: mode elf_i386
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crt1.o
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crti.o
/usr/lib/gcc/i486-linux-gnu/4.3.2/crtbegin.o
/tmp/cc5l0KO5.o
(/home/drl/gmp/lib/libgmp.a)lt3-add_ui.o
(/home/drl/gmp/lib/libgmp.a)lt22-init.o
(/home/drl/gmp/lib/libgmp.a)lt29-iset_str.o
(/home/drl/gmp/lib/libgmp.a)lt33-mul_ui.o
(/home/drl/gmp/lib/libgmp.a)realloc.o
(/home/drl/gmp/lib/libgmp.a)lt43-set_str.o
(/home/drl/gmp/lib/libgmp.a)mp_bases.o
(/home/drl/gmp/lib/libgmp.a)mul_1.o
(/home/drl/gmp/lib/libgmp.a)lt88-set_str.o
(/home/drl/gmp/lib/libgmp.a)printf.o
(/home/drl/gmp/lib/libgmp.a)printffuns.o
(/home/drl/gmp/lib/libgmp.a)assert.o
(/home/drl/gmp/lib/libgmp.a)memory.o
(/home/drl/gmp/lib/libgmp.a)mp_dv_tab.o
(/home/drl/gmp/lib/libgmp.a)tal-reent.o
(/home/drl/gmp/lib/libgmp.a)add_n.o
(/home/drl/gmp/lib/libgmp.a)dive_1.o
(/home/drl/gmp/lib/libgmp.a)lt82-mul.o
(/home/drl/gmp/lib/libgmp.a)mul_n.o
(/home/drl/gmp/lib/libgmp.a)sqr.o
(/home/drl/gmp/lib/libgmp.a)mul_basecase.o
(/home/drl/gmp/lib/libgmp.a)sqr_basecase.o
(/home/drl/gmp/lib/libgmp.a)nussbaumer_mul.o
(/home/drl/gmp/lib/libgmp.a)toom22_mul.o
(/home/drl/gmp/lib/libgmp.a)toom32_mul.o
(/home/drl/gmp/lib/libgmp.a)toom42_mul.o
(/home/drl/gmp/lib/libgmp.a)toom33_mul.o
(/home/drl/gmp/lib/libgmp.a)toom43_mul.o
(/home/drl/gmp/lib/libgmp.a)toom53_mul.o
(/home/drl/gmp/lib/libgmp.a)toom63_mul.o
(/home/drl/gmp/lib/libgmp.a)toom44_mul.o
(/home/drl/gmp/lib/libgmp.a)toom6h_mul.o
(/home/drl/gmp/lib/libgmp.a)toom6_sqr.o
(/home/drl/gmp/lib/libgmp.a)toom8h_mul.o
(/home/drl/gmp/lib/libgmp.a)toom8_sqr.o
(/home/drl/gmp/lib/libgmp.a)toom_couple_handling.o
(/home/drl/gmp/lib/libgmp.a)toom2_sqr.o
(/home/drl/gmp/lib/libgmp.a)toom3_sqr.o
(/home/drl/gmp/lib/libgmp.a)toom_eval_dgr3_pm1.o
(/home/drl/gmp/lib/libgmp.a)toom_eval_dgr3_pm2.o
(/home/drl/gmp/lib/libgmp.a)toom_eval_pm1.o
(/home/drl/gmp/lib/libgmp.a)toom_eval_pm2.o
(/home/drl/gmp/lib/libgmp.a)toom_eval_pm2exp.o
(/home/drl/gmp/lib/libgmp.a)toom_eval_pm2rexp.o
(/home/drl/gmp/lib/libgmp.a)toom_interpolate_5pts.o
(/home/drl/gmp/lib/libgmp.a)toom_interpolate_6pts.o
(/home/drl/gmp/lib/libgmp.a)toom_interpolate_7pts.o
(/home/drl/gmp/lib/libgmp.a)toom_interpolate_8pts.o
(/home/drl/gmp/lib/libgmp.a)toom_interpolate_12pts.o
(/home/drl/gmp/lib/libgmp.a)toom_interpolate_16pts.o
(/home/drl/gmp/lib/libgmp.a)mulmod_bnm1.o
(/home/drl/gmp/lib/libgmp.a)sqrmod_bnm1.o
(/home/drl/gmp/lib/libgmp.a)bdiv_dbm1c.o
(/home/drl/gmp/lib/libgmp.a)copyi.o
(/home/drl/gmp/lib/libgmp.a)addlsh1_n.o
(/home/drl/gmp/lib/libgmp.a)rsh1add_n.o
(/home/drl/gmp/lib/libgmp.a)doprnt.o
(/home/drl/gmp/lib/libgmp.a)doprntf.o
(/home/drl/gmp/lib/libgmp.a)doprnti.o
(/home/drl/gmp/lib/libgmp.a)mp_minv_tab.o
(/home/drl/gmp/lib/libgmp.a)set_si.o
(/home/drl/gmp/lib/libgmp.a)get_str.o
(/home/drl/gmp/lib/libgmp.a)lt20-get_str.o
(/home/drl/gmp/lib/libgmp.a)lt42-set_si.o
(/home/drl/gmp/lib/libgmp.a)lt60-get_str.o
(/home/drl/gmp/lib/libgmp.a)lt68-set_si.o
(/home/drl/gmp/lib/libgmp.a)sub_n.o
(/home/drl/gmp/lib/libgmp.a)addmul_1.o
(/home/drl/gmp/lib/libgmp.a)submul_1.o
(/home/drl/gmp/lib/libgmp.a)lshift.o
(/home/drl/gmp/lib/libgmp.a)rshift.o
(/home/drl/gmp/lib/libgmp.a)mul_fft.o
(/home/drl/gmp/lib/libgmp.a)lt87-get_str.o
(/home/drl/gmp/lib/libgmp.a)lt98-tdiv_qr.o
(/home/drl/gmp/lib/libgmp.a)sbpi1_div_qr.o
(/home/drl/gmp/lib/libgmp.a)dcpi1_div_qr.o
(/home/drl/gmp/lib/libgmp.a)mu_div_qr.o
(/home/drl/gmp/lib/libgmp.a)copyd.o
(/home/drl/gmp/lib/libgmp.a)invert_limb.o
(/home/drl/gmp/lib/libgmp.a)errno.o
(/home/drl/gmp/lib/libgmp.a)mp_bpl.o
(/home/drl/gmp/lib/libgmp.a)divrem_1.o
(/home/drl/gmp/lib/libgmp.a)divrem_2.o
(/home/drl/gmp/lib/libgmp.a)lshiftc.o
(/home/drl/gmp/lib/libgmp.a)invertappr.o
(/home/drl/gmp/lib/libgmp.a)sbpi1_divappr_q.o
-lstdc++ (/usr/lib/gcc/i486-linux-gnu/4.3.2/libstdc++.so)
-lm (/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/libm.so)
-lgcc_s (/usr/lib/gcc/i486-linux-gnu/4.3.2/libgcc_s.so)
/lib/libc.so.6
(/usr/lib/libc_nonshared.a)elf-init.oS
/lib/ld-linux.so.2
-lgcc_s (/usr/lib/gcc/i486-linux-gnu/4.3.2/libgcc_s.so)
/usr/lib/gcc/i486-linux-gnu/4.3.2/crtend.o
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crtn.o
2470450

At first I thought the link had included everything in libgmp.a, but there are 450+ entries (according to nm | grep T | wc, and ar t | wc), so I concluded it was a selective link.

I am not using OS X, but I'd guess it's worth a try to do it this way if you cannot install into /lib, /usr/lib.

Good luck ... cheers, drl
This User Gave Thanks to drl For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

Linking problem while linking to shared library

Hi I'm getting ld: fatal: option -h and building a dynamic executable are incompatible ld: fatal: Flags processing errors When I run ld -shared -L/usr/dt/lib -lDtSvc -o builtin.so Workspace.o after running gcc -fPIC -I/usr/X11R6/include -I/usr/dt/include -c Workspace.c I'm... (6 Replies)
Discussion started by: laho
6 Replies

2. HP-UX

GMP multi precision math library

Hello all, I'm having trouble building the GNU Multi Precision (GMP 4.1.3) on the HP Intel Itanium 2 HP-UX 11i I'm hoping someone out there has had some experience building GMP on this platform. After running the ./configure and doing a make I get an error saying: `.rodata` is not a section ... (3 Replies)
Discussion started by: vyl
3 Replies

3. UNIX for Dummies Questions & Answers

Link error while linking a shared library in unix

Getting the following error , ld: /opt/syncsort39/lib/libsyncsort.sl: Mismatched ABI. 64-bit PA shared library found in 32-bit link. Is there any difference in the ld options in opt file while linking a 64 bit shared library ? Or is the problem because we are trying to link both 32 bit and 64... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

4. AIX

Help while linking the library in AIX

Hi, I have one library(libfoo.a) that is folder /home/xyz and my c program is in /home/xyz/cprog. Whenever I issue cc command cc -o test test.c -lfoo , i get the error /usr/bin/ld: cannot find -lfoo. echo $PATH has already listing of /home/xyz variable, even LIBPATH also has same entry... (0 Replies)
Discussion started by: rishisoft1
0 Replies

5. Shell Programming and Scripting

How to change a Makefile from building static library to shared library?

Hi: I have a library that it only offers Makefile for building static library. It built libxxx.a file. How do I in any way build a shared library? (either changin the Makefile or direct script or command to build shared library) Thanks. (1 Reply)
Discussion started by: cpthk
1 Replies

6. OS X (Apple)

Linking to a shared library

I'm trying to get Valgrind to work with an openmpi application in OS X. However I want to hardcode the path to a shared library called libmpiwrap-amd64-darwin.so into my application so that it is available at runtime. In Linux this is relatively simple, I would just add the option... (0 Replies)
Discussion started by: Valgrinder
0 Replies

7. Linux

./configure problem for libsf library due to apparently missing libdb library.

Hello, ./configure script fails to configure libsf. Please check the following last few lines of configure script error. checking for db1/db.h... no checking for db.h... yes checking for dbopen in -ldb1... no configure: error: No libdb? No libsf. But find command shows the following; ... (4 Replies)
Discussion started by: vectrum
4 Replies

8. AIX

Add shared members from library to same library in a different directory

I'm trying to install libiconv to AIX 7.1 from an rpm off of the perzl site. The rpm appears to install but I get this error message. add shr4.o shared members from /usr/lib/libiconv.a to /opt/freeware/lib/libiconv.a add shr.o shared members from /usr/lib/libiconv.a to ... (5 Replies)
Discussion started by: kneemoe
5 Replies

9. UNIX for Advanced & Expert Users

Installing recent version of gmp

I want to install a recent version of gmp on Fedora. Tried to use yum # yum list | grep gmp gmp.i686 4.3.1-6.fc13 @fedora gmp.x86_64 4.3.1-6.fc13 @fedora gmp-devel.x86_64 ... (3 Replies)
Discussion started by: kristinu
3 Replies

10. Programming

C++ linking library to a library

Hi All, My application main engine will use a shared library where we do many operation. We are trying to implement the linear algebra operation on the shared library for that I need to link my shared library to the lapack library in /usr/lib. Below is my make file. Can you please let me... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies
All times are GMT -4. The time now is 12:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy