Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6808601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:58:35+00:00 2026-05-26T19:58:35+00:00

The GMP docs say that static linking may provide a small performance improvement. I

  • 0

The GMP docs say that static linking may provide a small performance improvement.

I am having a problem getting it to staticly link libgmp on my Linux systems. I’ve narrowed down the issue I’m having to a tiny test case.

gmptest.c

#include <gmp.h>

int main(int argc, char** argv) {
    mpz_t foo;
    mpz_init(foo);
    return 0;
}

Makefile:

all: clean gmptest static

clean:
    rm -f *.s
    rm -f *.o
    rm -f gmptest
    rm -f static-gmptest

gmptest: Makefile gmptest.c
    gcc -std=c99 -O3 -lgmp gmptest.c -o gmptest

static: clean Makefile gmptest.c
    gcc -std=c99 -O3 -static /usr/lib/libgmp.a gmptest.c -o static-gmptest

The non-static binary is compiled and linked without any issues, but ‘Make static’ produces:

gcc -std=c99 -O3 -static /usr/lib/libgmp.a gmptest.c -o static-gmptest
/tmp/ccWSFke9.o: In function `main':
gmptest.c:(.text+0x8): undefined reference to `__gmpz_init'
collect2: ld returned 1 exit status
make: *** [static] Error 1

The library does exist:

chris@vostro:~/Dropbox/static$ ls -lA /usr/lib/libgmp.a 
-rw-r--r-- 1 root root 1041666 2010-02-26 13:20 /usr/lib/libgmp.a

I have also tried -lgmp for the static linking, but the error is the same.

This is all on Ubuntu 10.04 and 10.10 AMD64.

Can some enlighten me as to the obvious error I’m making?

Thanks,

Chris.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:58:35+00:00Added an answer on May 26, 2026 at 7:58 pm

    Try

     gcc -std=c99 -O3 -static gmptest.c -lgmp -o static-gmptest
    

    since libraries should always be linked in the good order, and after the program or object files using them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a small library for RSA or DSA without any dependencies like GMP
I'm currently learning libgmp and to that end I'm writing a small program which
I'm using the GMP library to make a Pi program, that will calculate about
It seems that GMP provides only string serialization of the mpf (floating point) type:
I have a php application that uses the bitwise functions from the GMP library
Using GMP on c, I have a big integer mpz_t n in decimal form,
I'm using GMP to calculate very large factorials (e.g. 234234!). Is there any way
When I call get_d() on a MPQ variable in the GMP library, I only
Is it possible to use custom types in OpenCL kernel like gmp types (mpz_t,
How to know the size of a declared variable in GMP??or how can we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.