1

I have downloaded and installed the NTL library on my Ubuntu. I'm currently using gedit to write my program and having included this ZZ.h header in my program. This is how i compile my program in the terminal: - g++ keygen.cpp -o keygen -I ../include -L ../lib -lntl -lm.

I'm pretty sure this line is correct but for some unknown reason, i get the following error:

KeyGen.cpp:9:20: error: NTL/ZZ.h: No such file or directory
KeyGen.cpp:15: error: expected constructor, destructor, or type conversion before ‘int’

The solution seems pretty straightforward to me: which is to add the NTL library directly to my program folder. I did just that, but still i get the same error.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Joel Seah
  • 674
  • 3
  • 13
  • 34
  • Do you actually have NTL/ZZ.h header in paths you g++ uses for headers. Try to run `cpp -I ../include -x c++ -v` to get the whole list of include directories – user3159253 Jan 30 '14 at 13:07
  • @user3159253 so meaning to say i MUST see NTL/ZZ.h in the include directories? – Joel Seah Jan 30 '14 at 13:10
  • Surely you do. In one of include directories there should be a subdirectory called NTL and readable ZZ.h in it. – user3159253 Jan 30 '14 at 13:17
  • How did you install NTL library? From the package or from sources? I've checked ZZ.h does exist in /include/NTL/ – user3159253 Jan 30 '14 at 13:22
  • @user3159253 I installed the library following the instructions on the NTL website. Icreated a folder called 'include' within the `.cpp` folder and included the NTL library in that folder already. Since i don't see it.. What should i do? – Joel Seah Jan 30 '14 at 13:23

3 Answers3

2

If you don't need the latest (6.0.0) version of NTL you may do as follows in your Ubuntu:

user@host:~$ sudo apt-get install libntl-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libntl-5.4.2
The following NEW packages will be installed:
  libntl-5.4.2 libntl-dev
0 upgraded, 2 newly installed, 0 to remove and 112 not upgraded.
Need to get 2,035 kB of archives.
After this operation, 7,016 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://ftp.de.debian.org/debian/ squeeze/main libntl-5.4.2 amd64 5.4.2-4 [767 kB]
Get:2 http://ftp.de.debian.org/debian/ squeeze/main libntl-dev amd64 5.4.2-4 [1,268 kB]
Fetched 2,035 kB in 2s (1,017 kB/s)   
Selecting previously deselected package libntl-5.4.2.
(Reading database ... 59184 files and directories currently installed.)
Unpacking libntl-5.4.2 (from .../libntl-5.4.2_5.4.2-4_amd64.deb) ...
Selecting previously deselected package libntl-dev.
Unpacking libntl-dev (from .../libntl-dev_5.4.2-4_amd64.deb) ...
Can not write log, openpty() failed (/dev/pts not mounted?)
Setting up libntl-5.4.2 (5.4.2-4) ...
Setting up libntl-dev (5.4.2-4) ..
user@host:~$ 

after that the complete compiled NTL library with all development headers is installed in your system and you may compile your program with it without any additional -I<path>.

If you need a newer version that your distro has (check http://packages.ubuntu.com/en/source/trusty/ntl) you may try to build the library package yourself.

user3159253
  • 16,836
  • 3
  • 30
  • 56
  • I tried ur way but the terminal tells me that the package could not be found. – Joel Seah Jan 30 '14 at 13:58
  • Hmm what ubuntu do you have? – user3159253 Jan 30 '14 at 14:41
  • Well, you may run `apt-cache policy` to check what apt repositories are in use. Make sure that `universe` repository is on (the third field in the output, smth like `saucy/universe` or `raring/universe`. Then try to perform `apt-cache search libntl-dev`. – user3159253 Jan 30 '14 at 15:08
  • I tried the `search` and nothing came up. And yes the `universe` repo is on the third output. – Joel Seah Jan 30 '14 at 15:26
  • I think its solved. Now when i compile again, it gives me another error: `undefined reference to NTL..` – Joel Seah Jan 30 '14 at 15:50
  • If "reference" is on stage then you've got to the linker. Try to specify a full path to libntl.a in the compilation command line. – user3159253 Jan 30 '14 at 15:56
  • Nevertheless, what is your Ubuntu version? What word do see before `universe` in the `apt-cache policy` output? – user3159253 Jan 30 '14 at 15:57
  • 500 http://us.archive.ubuntu.com/ubuntu/ lucid/universe Packages release v=10.04,o=Ubuntu,a=lucid,n=lucid,l=Ubuntu,c=universe origin us.archive.ubuntu.com – Joel Seah Jan 30 '14 at 15:59
  • Uff, pretty vintage. Have you considered a system upgrade? Likely 10.04 Desktop is unsupported now and even security fixes aren't released anymore. Anyway NTL library does exist even in such an "ancient" Ubuntu http://packages.ubuntu.com/lucid/libntl-dev . – user3159253 Jan 30 '14 at 16:11
  • Have you managed to link your program with explicit specification of libntl.a, smth like `g++ -o keygen keygen.cpp /path/to/libntl.a -lm`? – user3159253 Jan 30 '14 at 16:13
  • Erm no.. I'm doing this now : `g++ keygen.cpp -I include -L lib -lntl -lm` – Joel Seah Jan 30 '14 at 16:13
  • When you simply specify -l then the linker searches "system-default" libraries paths such as /lib and /usr/lib and those you specified via -L linker flag. Therefore if your libntl.so isn't in those paths, the linker fails. Moreover if you use a dynamically loaded library (libntl.so or libntl.so.) then upon application startup your library should be located somewhere in paths well known to Linux DLL loader (ld.so), see `man ld.so`. – user3159253 Jan 31 '14 at 10:59
  • If you don't wish to bother yourself with these gory details (I do understand you :) ) you may prefer to link a static version of NTL library, called libntl.a. Just locate where it resides and put the full path to it into the compilation/linkage command, as suggested in my previous comment. – user3159253 Jan 31 '14 at 10:59
  • Okay I did something like this `g++ keygen -I include -L //lib/libntl.a -Intl -lm`. It still gives me the same error. Could something be wrong with the compilation line? – Joel Seah Jan 31 '14 at 11:19
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/46521/discussion-between-user3159253-and-joel-seah) – user3159253 Jan 31 '14 at 14:31
0

The problem with your attempt to compile and output an executable file appears to be compiler's inability to link the necessary library after obtaining an object .o file.

Many people often test the point of fault by separating the two stages by first compiling g++ -c then by linking the libraries for an executable g++ -o. Although -Wall switch does not always work, trying it to provide you with as much information as possible during compilation can also be helpful.

Check this webpage. As for using different switches to link libraries try this webpage.

I'm not certain if it was a typo; but I wonder if the space between the switch and directory:
-I ../include and -L ../lib
was the problem.

Community
  • 1
  • 1
  • Well, he hasn't reached the link stage. `KeyGen.cpp:9:20: error: NTL/ZZ.h: No such file or directory` is the message from compiler, more precisely, from preprocessor – user3159253 Jan 30 '14 at 15:13
0

You said in comments:

Icreated a folder called 'include' within the .cpp folder and included the NTL library in that folder already

But your compilation command says:

g++ keygen.cpp -o keygen -I ../include -L ../lib -lntl -lm.

It seems to me, you meant:

g++ keygen.cpp -o keygen -I ./include -L ../lib -lntl -lm.
#                           ^^^^^^^^^

since .. goes up one directory.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055