Ayush choubey
Ayush choubey

Reputation: 616

Trouble including NSS header Files

Very recently, I had this idea to start using Mozilla NSS and to learn to use it, so that somewhere in the future, i can use it, or can atleast start contributing to it.

So i went to its Website and cloned it source code into a director "NSS" using mercurial

Then I used

make nss_build_all

instead of

gmake nss_build_all

Note : I don't know, if it makes a difference, gmake is just GNU Make

This make command created a dist folder outside the nss folder. So, Now my NSS folder has 3 folders nss,nspr,dist.

In .bashrc i added a line at the end

export LD_LIBRARY_PATH=/home/ayusun/workspace/NSS/dist/Linux3.5_x86_glibc_PTH_DBG.OBJ/lib

Then i went over to this Sample code, did a copy paste and saved it in my NSS Folder. And then i tried to compile it, but it failed, stating it couldn't find iostream.h, I went over and changed the location of header files

So

<iostream.h> became <iostream>
"pk11pub.h" became "nss/lib/pk11wrap/pk11pub.h"
"keyhi.h" became "nss/lib/cryptohi/keyhi.h"
"nss.h" became "nss/lib/nss/nss.h"

I tried compiling again but this time error came, that it couldn't find "planera.h" which is actually present in dist/*.OBJ/include/ which is a link to a file planeras.h in nspr

And so i don't know, how to include these files anymore.

I always have trouble when it comes to include 3rd party header files.

Thanks

Upvotes: 3

Views: 2765

Answers (1)

Johann Oskarsson
Johann Oskarsson

Reputation: 816

This is an old question, but I'll answer it anyway for future reference.

The simplest way is just to use the NSS package for your operating system.
Then you can use things like nss-config --cflags, nss-config --libs, nspr-config --cflags and nspr-config --libs and add that to your CFLAGS and LDFLAGS as appropriate.

For those who do decide to compile their own NSS, I'll give the quick overview.

The NSS headers are in dist/public. Add -I/path/to/dist/public to your compiler command line. The NSPR headers are in dist/Debug/include¹ so add -I/path/to/dist/Debug/include to your comiler command line.

Now you can use #include <nspr/prio.h> and #include <nss/nss.h> and friends.

The NSS code relies on directly uncluding the NSPR headers, so you'll need to add -I/path/to/dist/Debug/include/nspr for it to find things like plarena.h. Or you could do the same and not prefix your includes like I did above. It's up to you.

Now add -L/path/to/dist/Debug/lib and -lnss3 -lnspr4 to your linker command line. You may want to also add -rpath /path/to/dist/Debug/lib for the runtime link path, or copy them to a system directory or use LD_LIBRARY_PATH.

I hope this gets you started.

¹ This actually depends on your operating system and build type. I hope you can figure out the name of the actual Debug directory in your case.

Upvotes: 2

Related Questions