Fedora Linux Support Community & Resources Center
  #1  
Old 12th September 2009, 11:26 AM
Jakiro Offline
Registered User
 
Join Date: Mar 2009
Location: Singapore
Posts: 8
linuxfedorafirefox
compiling c++ programs with NTL library

Hi, does anyone know how to compile c++ programs that uses the NTL library( http://www.shoup.net/ntl )?

I have installed the package ntl-devel by using yum.
Now I have a simple c++ program that uses NTL:
Code:
#include <NTL/ZZ.h>

NTL_CLIENT

int main()
{
   ZZ a, b, c; 

   cin >> a; 
   cin >> b; 
   c = (a+1)*(b+1);
   cout << c << "\n";

   return 0
}
How do I compile this program with g++?
The usual
Code:
g++ example.cpp -o example
does not work.
Reply With Quote
  #2  
Old 12th September 2009, 11:43 AM
markkuk Offline
Registered User
 
Join Date: Apr 2005
Location: Finland
Posts: 5,076
linuxfirefox
Install the gmp-devel package and link with both ntl and gmp libraries:
Code:
g++ example.cpp -o example -lntl -lgmp
You must also fix the example code by adding the missing "#include <iostream>" and "using namespace std;" statements.
Reply With Quote
  #3  
Old 12th September 2009, 12:15 PM
Jakiro Offline
Registered User
 
Join Date: Mar 2009
Location: Singapore
Posts: 8
linuxfedorafirefox
Now it works. Thanks a lot.
Reply With Quote
  #4  
Old 27th June 2012, 04:04 AM
bron1 Offline
Registered User
 
Join Date: Jun 2012
Location: Milky Way Galaxy
Posts: 1
linuxubuntufirefox
Re: compiling c++ programs with NTL library

Actually, only two things were needed.

(1) The last line of c++ code needs a semicolon, i.e.
Quote:
return 0;
(2) The g++ call needs only the -lntl flag, i.e.
Quote:
g++ example.cpp -o example -lntl
(assuming NTL is was installed to default location which is usually /usr/local).

The usual #include statement and namespace statement mentioned by markkuk are not necessary nor is the -lgmp flag for g++ unless NTL was compiled with GMP. However, including all these does not hurt.
Reply With Quote
  #5  
Old 27th June 2012, 04:42 AM
RupertPupkin's Avatar
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 4,613
linuxfedorafirefox
Re: compiling c++ programs with NTL library

Quote:
Originally Posted by bron1 View Post
assuming NTL is was installed to default location which is usually /usr/local
Fedora packages never install under /usr/local. For example, the 64-bit Fedora 17 ntl and ntl-devel packages put the libraries and headers in /usr/lib64 and /usr/include, respectively. You are correct that only "g++ example.cpp -o example -lntl" is needed to compile that code, as long as you install the ntl/ntl-devel packages via yum.

On a side note, I never knew about NTL until now, glad to learn about it. For arbitrary-length integer computations I'm curious to see how it compares to GMP, performance-wise. There's a thread here about using GMP to compute the 46th Mersenne prime. Maybe I'll try to do the same with NTL, though it appears that NTL was compiled with GMP!
Code:
$ ldd /usr/lib64/libntl.so.0.1.0
        linux-vdso.so.1 =>  (0x00007fffcc267000)
        libgmp.so.10 => /lib64/libgmp.so.10 (0x00007f55dfedb000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f55dfbd7000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f55df8dc000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f55df525000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f55df30f000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f55e0541000)
__________________
OS: Fedora 18 x86_64 | CPU: AMD64 3700+ 2.2GHz | RAM: 2GB PC3200 DDR | Disk: 160GB PATA | Video: ATI Radeon 7500 AGP 64MB | Sound: Turtle Beach Santa Cruz CS4630 | Ethernet: Realtek 8110SC
Reply With Quote
  #6  
Old 27th June 2012, 04:51 PM
RupertPupkin's Avatar
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 4,613
linuxfedorafirefox
Re: compiling c++ programs with NTL library

Well it looks like NTL is nowhere near as fast as GMP. I used this code (mersenneNTL.cpp)
Code:
#include <NTL/ZZ.h>

NTL_CLIENT

int main(int argc, char *argv[]) {
   char *endptr;
   unsigned long int a = strtoul(argv[1],&endptr,10);
   ZZ b = power2_ZZ(a) - 1;
   cout << b;
   return 0;
}
and compiled and ran it like this
Code:
$ g++ -o mersenneNTL mersenneNTL.cpp -lntl
$ time ./mersenneNTL 43112609 > M46
to compute the 46th Mersenne prime (2^43112609 - 1). After 21 minutes (with my cpu heating up to 140F) and still not finished I finally had to kill it. With GMP it takes about 6 seconds to finish. I tried removing the last digit (so that it'd compute 2^4311260 - 1), and the NTL version did finish in about 17 seconds, whereas the GMP version did it in less than a second.

I think the bottleneck with NTL might be the cout statement. GMP has a specialized printf function called gmp_printf that recognizes the large integer type, but for NTL I couldn't find an equivalent so I stuck with cout.
__________________
OS: Fedora 18 x86_64 | CPU: AMD64 3700+ 2.2GHz | RAM: 2GB PC3200 DDR | Disk: 160GB PATA | Video: ATI Radeon 7500 AGP 64MB | Sound: Turtle Beach Santa Cruz CS4630 | Ethernet: Realtek 8110SC
Reply With Quote
Reply

Tags
compiling, library, ntl, programs

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Boost library compiling errors redawn Programming & Packaging 5 4th April 2009 08:41 PM
Problem compiling Mesa library Shai Using Fedora 3 24th October 2007 03:20 PM
Compiling Allegro game library. marcin2 Using Fedora 0 28th June 2005 01:36 AM


Current GMT-time: 03:42 (Sunday, 19-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat