mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2009-02-13, 20:05   #1
Raman
Noodles
 
Raman's Avatar
 
"Mr. Tuch"
Dec 2007
Chennai, India

3×419 Posts
Default Compiling my first program by using GMP

Just this is a program in C++ to trial divide integers < 4294967296

Code:
#include<iostream.h>
main()
{
unsigned long a;
unsigned long b;
cout<<"Number: ";
cin>>a;
while(a%2==0)
{
cout<<"PRIME FACTOR 2"<<endl;
a=a/2;
}
b=3;
while(b*b<=a)
{
if(a%b==0)
{
cout<<"PRIME FACTOR "<<b<<endl;
a=a/b;
continue;
}
b=b+2;
}
cout<<"PRIME FACTOR "<<a<<endl;
}
I am trying to write the same code by using GMP library and trying to compile it but I am unable to do so.

Code:
#include<iostream.h>
#include<gmp.h>
main()
{
mpz_t a;
mpz_t b;
cout<<"Number: ";
mpz_inp_raw(a,NULL);
while(mpz_divisible_ui_p(a,2))
{
cout<<"PRIME FACTOR 2"<<endl;
mpz_tdiv_q_ui(a,a,2);
}
mpz_set_ui(b,3);
mpz_t c;
mpz_sqrt(c,a);
while(mpz_cmp(b,c)<=0)
{
if(mpz_divisible_p(a,b))
{
cout<<"PRIME FACTOR ";
mpz_out_raw(NULL,b);
cout<<endl;
mpz_tdiv_q(a,a,b);
continue;
}
mpz_add_ui(b,b,2);
}
cout<<"PRIME FACTOR ";
mpz_out_raw(NULL,a);
cout<<endl;
}
In Borland C++, I put all the GMP files into the <include> folder
but I am getting a series of errors

In MinGW, I installed the GMP library as it is suggested,
but still I could not include the library files. Could someone
please help me out?

Certainly, JAVA is not a good language for FFT multiplication
for p-1 or p+1 or ECM.
Code:
In file included from c:/mingw/include/c++/3.2.3/backward/iostream.h:31,
                 from Test.cpp:1:
c:/mingw/include/c++/3.2.3/backward/backward_warning.h:32:2: warning: #warning T                                             his file includes at least one deprecated or antiquated header. Please consider                                              using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examp                                             les include substituting the <X> header for the <X.h> header for C++ includes, o                                             r <sstream> instead of the deprecated header <strstream.h>. To disable this warn                                             ing use -Wno-deprecated.
Test.cpp:2:16: gmp.h: No such file or directory
Test.cpp: In function `int main()':
Test.cpp:5: `mpz_t' undeclared (first use this function)
Test.cpp:5: (Each undeclared identifier is reported only once for each function 
   it appears in.)
Test.cpp:5: parse error before `;' token
Test.cpp:8: `a' undeclared (first use this function)
Test.cpp:8: `mpz_inp_raw' undeclared (first use this function)
Test.cpp:9: `mpz_divisible_ui_p' undeclared (first use this function)
Test.cpp:12: `mpz_tdiv_q_ui' undeclared (first use this function)
Test.cpp:14: `b' undeclared (first use this function)
Test.cpp:14: `mpz_set_ui' undeclared (first use this function)
Test.cpp:15: parse error before `;' token
Test.cpp:16: `c' undeclared (first use this function)
Test.cpp:16: `mpz_sqrt' undeclared (first use this function)
Test.cpp:17: `mpz_cmp' undeclared (first use this function)
Test.cpp:19: `mpz_divisible_p' undeclared (first use this function)
Test.cpp:22: `mpz_out_raw' undeclared (first use this function)
Test.cpp:24: `mpz_tdiv_q' undeclared (first use this function)
Test.cpp:27: `mpz_add_ui' undeclared (first use this function)

Last fiddled with by Raman on 2009-02-13 at 20:06
Raman is offline   Reply With Quote
Old 2009-02-13, 20:53   #2
rogue
 
rogue's Avatar
 
"Mark"
Apr 2003
Between here and the

13×503 Posts
Default

After you did make, did you do both "make check" and "make install"? Is the installation directory in the include path?
rogue is offline   Reply With Quote
Old 2009-02-13, 21:21   #3
Raman
Noodles
 
Raman's Avatar
 
"Mr. Tuch"
Dec 2007
Chennai, India

3·419 Posts
Default

Gmp-4.2.4 has been extracted to /home/gmp-4.2.4
I ran ./configure followed by make

Make check runs okay

Make install says so the following thing

Code:
test -z "/usr/local/info" || mkdir -p -- . "/usr/local/info"
 /bin/install -c -m 644 './gmp.info' '/usr/local/info/gmp.info'
 /bin/install -c -m 644 './gmp.info-1' '/usr/local/info/gmp.info-1'
 /bin/install -c -m 644 './gmp.info-2' '/usr/local/info/gmp.info-2'
 install-info --info-dir='/usr/local/info' '/usr/local/info/gmp.info'
make[3]: Leaving directory `/home/gmp-4.2.2/doc'
make[2]: Leaving directory `/home/gmp-4.2.2/doc'
make[2]: Entering directory `/home/gmp-4.2.2'
make[3]: Entering directory `/home/gmp-4.2.2'
test -z "/usr/local/lib" || mkdir -p -- . "/usr/local/lib"
 /bin/sh ./libtool --mode=install /bin/install -c  'libgmp.la' '/usr/local/lib/l                                             ibgmp.la'
/bin/install -c .libs/libgmp.lai /usr/local/lib/libgmp.la
/bin/install -c .libs/libgmp.a /usr/local/lib/libgmp.a
chmod 644 /usr/local/lib/libgmp.a
ranlib /usr/local/lib/libgmp.a
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-LLIBDIR' linker flag

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
test -z "/usr/local/include" || mkdir -p -- . "/usr/local/include"
 /bin/install -c -m 644 'gmp.h' '/usr/local/include/gmp.h'
test -z "/usr/local/include" || mkdir -p -- . "/usr/local/include"
make  install-data-hook
make[4]: Entering directory `/home/gmp-4.2.2'

+-------------------------------------------------------------+
| CAUTION:                                                    |
|                                                             |
| If you have not already run "make check", then we strongly  |
| recommend you do so.                                        |
|                                                             |
| GMP has been carefully tested by its authors, but compilers |
| are all too often released with serious bugs.  GMP tends to |
| explore interesting corners in compilers and has hit bugs   |
| on quite a few occasions.                                   |
|                                                             |
+-------------------------------------------------------------+

make[4]: Leaving directory `/home/gmp-4.2.2'
make[3]: Leaving directory `/home/gmp-4.2.2'
make[2]: Leaving directory `/home/gmp-4.2.2'
make[1]: Leaving directory `/home/gmp-4.2.2'
gmp.h is currently present so in the /usr/local/include directory and no other files are there in that directory.

I am unable to include so that header file
from the /home/Factor directory

Any suggestions for the syntax on how to do that up so?
Raman is offline   Reply With Quote
Old 2009-02-14, 02:17   #4
rogue
 
rogue's Avatar
 
"Mark"
Apr 2003
Between here and the

653910 Posts
Default

When compiling use "-I /usr/local/include". When linking use "-L /usr/local/lib".
rogue is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
compiling GMP-ECM ATH GMP-ECM 69 2017-01-04 12:03
AArch64 Compiling packetnathan Software 2 2016-12-23 01:36
compiling question ATH GMP-ECM 19 2009-04-22 09:53
Compiling 24.14 CBoland Software 6 2007-08-01 00:11
Compiling ECM 5.0.3 for windows BotXXX Factoring 25 2005-09-13 12:24

All times are UTC. The time now is 12:50.


Fri Jan 28 12:50:33 UTC 2022 up 189 days, 7:19, 2 users, load averages: 1.60, 1.64, 1.58

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.

≠ ± ∓ ÷ × · − √ ‰ ⊗ ⊕ ⊖ ⊘ ⊙ ≤ ≥ ≦ ≧ ≨ ≩ ≺ ≻ ≼ ≽ ⊏ ⊐ ⊑ ⊒ ² ³ °
∠ ∟ ° ≅ ~ ‖ ⟂ ⫛
≡ ≜ ≈ ∝ ∞ ≪ ≫ ⌊⌋ ⌈⌉ ∘ ∏ ∐ ∑ ∧ ∨ ∩ ∪ ⨀ ⊕ ⊗ 𝖕 𝖖 𝖗 ⊲ ⊳
∅ ∖ ∁ ↦ ↣ ∩ ∪ ⊆ ⊂ ⊄ ⊊ ⊇ ⊃ ⊅ ⊋ ⊖ ∈ ∉ ∋ ∌ ℕ ℤ ℚ ℝ ℂ ℵ ℶ ℷ ℸ 𝓟
¬ ∨ ∧ ⊕ → ← ⇒ ⇐ ⇔ ∀ ∃ ∄ ∴ ∵ ⊤ ⊥ ⊢ ⊨ ⫤ ⊣ … ⋯ ⋮ ⋰ ⋱
∫ ∬ ∭ ∮ ∯ ∰ ∇ ∆ δ ∂ ℱ ℒ ℓ
𝛢𝛼 𝛣𝛽 𝛤𝛾 𝛥𝛿 𝛦𝜀𝜖 𝛧𝜁 𝛨𝜂 𝛩𝜃𝜗 𝛪𝜄 𝛫𝜅 𝛬𝜆 𝛭𝜇 𝛮𝜈 𝛯𝜉 𝛰𝜊 𝛱𝜋 𝛲𝜌 𝛴𝜎 𝛵𝜏 𝛶𝜐 𝛷𝜙𝜑 𝛸𝜒 𝛹𝜓 𝛺𝜔