Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with nettle gmake check
#1
help with nettle gmake check
so I have two questions actually if someone can shed some light.  I noticed when I compiled gmp-6.1.2 the "gmake check" scripts had a "-lgmp" flag for linking the gmp libraries, and now that I'm working with nettle-3.4 I'm noticing "-lnettle" flags.

so question 1:  how do these library flags work?  do I need to do something special for "-lgmp" or "-lnettle" to somehow now work?  They are clearly not part of MIPSPro, is this some sort of gcc-ism?  If they are in my lib path are they somehow now recognized?


Why am I doing this?  I wanted to compile wget, but it said it wanted gnutls, gnutls wants nettle, nettle wants gmp. so here I am.

question 2.  when doing the "gmake check" for nettle, I get:


Code:
gmake[1]: Entering directory `/usr/people/develop/dev/nettle/nettle-3.4/testsuite'
/usr/bin/cc -c99 -g0 -woff all -O2 -mips4 -L..  pss-mgf1-test.o testutils.o ../nettle-internal.o  -lnettle  -o pss-mgf1-test
ld32: ERROR   33 : Unresolved text symbol "nettle_pss_mgf1" -- 1st referenced by pss-mgf1-test.o.
        Use linker option -v to see when and which objects, archives and dsos are loaded.  
ld32: INFO    152: Output file removed because of error.
gmake[1]: *** [pss-mgf1-test] Error 2

i tried putting "-lnettle" after basically everything, but I'm not clear how this "-lnettle" is supposed to work, if work at all, and wtf is this about a program that cant resolve its own symbols?  Isn't that the point of compiling this program in the first place?  why does it seem like a catch 22?  "sorry, cant compile A because part-of-A is missing"

can someone help shed some light for me?

edit:

just to piggy back off this topic, I did a "gmake install" and everything went fine.  It for some reason installed everything into /usr/local/lib32 rather than /usr/local/lib, but that's ok, I copied everything over to /usr/local/lib

I tried to move on and build gnutls, and it complained:


Code:
./configure --prefix=/usr/local

<snip>

checking for NETTLE... no
configure: error: 
  ***
  *** Libnettle 3.4 was not found.

after I installed nettle, it doesn't seem these newer configure scripts can find it - any insight would be fabulous
(This post was last modified: 09-16-2018, 07:38 AM by gijoe77.)
gijoe77 Online
Tezro

Posts: 349
Threads: 23
Joined: Jun 2018
Find Reply
09-16-2018, 06:52 AM
#2
RE: help with nettle gmake check
-lnettle and -lgmp are linker shorthand for 'path/libnettle.so' and 'path/libgmp.so'
It is common practice to build a library of functions in a package and then link package programs with it. it to

The above sounds like Makefile problems to me. Try changing the order of libraries in the linker command
(This post was last modified: 09-16-2018, 08:33 AM by dexter1.)
dexter1 Offline
Global Moderator
******

Posts: 129
Threads: 8
Joined: May 2018
Find Reply
09-16-2018, 08:26 AM
#3
RE: help with nettle gmake check
For info, if you want to compile "wget" - you can either use the gnutls or openssl libraries - there's an either/or with those two.

I chose openssl as it was less pain (configure wget with "./configure --prefix=INSTALLDIR --with-ssl=openssl".

But back to your compilation issues - normally when you are running the configuration or build phase of a library with dependencies, you'll need to make sure that those dependencies can be found (as you've discovered).

What this means is that the libraries should be in the LD_LIBRARYN32_PATH and LDFLAGS, but header files should be in a path that is included in the CFLAGS/CPPFLAGS/CXXFLAGS.

The LDFLAGS "-L" means the linker can find them when trying to _link_ to them, the LD_LIBRARYN32_PATH means that they can be found at _runtime_ when attemping to launch a binary that needs the library.

I normally try and setup the header files using CPPFLAGS (C pre-processor flags) and the link directory with LDFLAGS.

For projects using autoconf/automake etc, setting these variables can be enough and the discovery script will work out the right "-lLIBNAME" pieces to add -> in most cases you shouldn't need to modify makefiles but sometimes that has to be done too.

Lets assume you're installing things under $INSTALLDIR, then the following should work:

Edit: Some variables to set before any of the below:


Code:
PATH=$INSTALLDIR/bin:$PATH
export PATH
LD_LIBRARYN32_PATH=$INSTALLDIR/lib:$LD_LIBRARYN32_PATH
export LD_LIBRARYN32_PATH



gmp-6.1.2:


Code:
CC=c99
CFLAGS="-O1"
LDFLAGS=""
export CC CFLAGS LDFLAGS
./configure --prefix=$INSTALLDIR


mpfr-4.0.1:


Code:
CC=c99
CXX=CC
CPPFLAGS="-I$INSTALLDIR/include"
CFLAGS="-O1"
CXXFLAGS="-O1"
LDFLAGS="-L$INSTALLDIR/lib"
export CC CXX CPPFLAGS CFLAGS CXXFLAGS LDFLAGS
./configure --prefix=$INSTALLDIR


nettle-3.4 (haven't run the tests on this yet, fwiw):


Code:
CC=c99
CXX=CC
CPPFLAGS="-I$INSTALLDIR/include"
CFLAGS="-O1"
CXXFLAGS="-O1"
LDFLAGS="-L$INSTALLDIR/lib"
export CC CXX CPPFLAGS CFLAGS CXXFLAGS LDFLAGS
./configure --prefix=$INSTALLDIR


One other thing I'd note - and it's not the case for the above packages - but  I've noticed that quite a few packages won't allow testing without a recent set of coreutils/m4/sed/grep/perl - so you'll need to have those in your path during "configure" and running of any tests.

Sometimes you'll have to set SHELL, SHELL_PATH, SHELL_CONFIG, PERL to be able to test (again - I don't think that's the case with the above packages).
(This post was last modified: 09-16-2018, 10:04 AM by mrthinlysliced.)
mrthinlysliced Online
Octane

Posts: 71
Threads: 5
Joined: May 2018
Find Reply
09-16-2018, 09:53 AM
#4
RE: help with nettle gmake check
Annd to get nettle tests to run to completion I had to patch it with this:

https://github.com/danielhams/didbs/blob...ixes.patch

Basically the standard C integer header file has guards to stop it being included in C++, but the C++ compiler isn't a new enough version of C++ that it has the "cstdint" header, so we define __c99 to work around that.
mrthinlysliced Online
Octane

Posts: 71
Threads: 5
Joined: May 2018
Find Reply
09-16-2018, 11:23 AM
#5
RE: help with nettle gmake check
(09-16-2018, 06:52 AM)gijoe77 Wrote: so question 1:  how do these library flags work?  do I need to do something special for "-lgmp" or "-lnettle" to somehow now work?  They are clearly not part of MIPSPro, is this some sort of gcc-ism?  If they are in my lib path are they somehow now recognized?

I think this got already answered before, but anyway:

-l and -L are flags destined for the linker, ld.

-l specifies the name of a library to include in the linking
-L specifies a directory to be searched for libraries

Example:

ld object.o -labc -o executable_name

Would search for a library named libabc.so or libabc.a in the standard library paths (/lib, /usr/lib, /lib32, /usr/lib32, and so on).

If you had this library in a nonstandard path, say /home/gijoe77/libabc.so, how can the linker find it? Using -L to specify *additional* library paths to be searched:

ld object.o -L/home/gijoe77 -labc -o executable_name


Some important points to note here:

-L directs the linker to search *first* in this path, and then in the standard paths. Therefore, it is always inclusive.
-l and -L order is important:

ld ... -L/home/gijoe77 -labc ... (search libabc.so first in /home/gijoe77 and then in standard paths)
ld ... -labc -L/home/gijoe77 ... (search libabc.so first in standard paths and then prepend /home/gijoe77 to standard paths for further searches)


(09-16-2018, 06:52 AM)gijoe77 Wrote: Why am I doing this?  I wanted to compile wget, but it said it wanted gnutls, gnutls wants nettle, nettle wants gmp. so here I am.

Big Grin

(09-16-2018, 06:52 AM)gijoe77 Wrote: question 2.  when doing the "gmake check" for nettle, I get:

Code:
gmake[1]: Entering directory `/usr/people/develop/dev/nettle/nettle-3.4/testsuite'
/usr/bin/cc -c99 -g0 -woff all -O2 -mips4 -L..  pss-mgf1-test.o testutils.o ../nettle-internal.o  -lnettle  -o pss-mgf1-test
ld32: ERROR   33 : Unresolved text symbol "nettle_pss_mgf1" -- 1st referenced by pss-mgf1-test.o.
        Use linker option -v to see when and which objects, archives and dsos are loaded.  
ld32: INFO    152: Output file removed because of error.
gmake[1]: *** [pss-mgf1-test] Error 2

Okay, so the object pss-mgf1-test.o needs a symbol named nettle_pss_mgf1 (variable or function) and the linker doesn't find it.

It could be a programming error that makes this unnecessary symbol be included *or* it really is needed by that object file but missing in the linker command line.

I would do a search for all possible object files *.o in the build dir, display their symbols and grep those with the needed symbol defined:

# find . -name '*.o' -exec nm \{\} \; -print > find.out
# grep -n nettle_pss_mgf1 find.out

What you are looking for are entries with defined symbols:

1234: nettle_pss_mgf1 | 0000000000000000 | T | 0000000000000008

(T stands for Text section - this symbol would be defined in the Text section of the corresponding object file)

It could also be D (D stands for Data section) if the symbol you are looking for is a variable:

1234: nettle_myvar | 0000000000000000 | D | 0000000000000008


In either case, discard entries where this symbol is undefined (U stands for Undefined):

666: nettle_pss_mgf1 | 0000000000000000 | U | 0000000000000008

Once you have found an entry with a defined symbol, open find.out in a text editor, go to the corresponding line (1234 in my example) and look for the object file name where this symbol is defined. Now include that file in the link command line.


If this doesn't work, tell me and we might find another way.

Good luck!
TruHobbyist Offline
O2

Posts: 43
Threads: 6
Joined: May 2018
Find Reply
09-16-2018, 11:42 AM
#6
RE: help with nettle gmake check
thank you everyone who help explain this to me.  I actually should have remembered about the CPPFLAGS and -I and -L paths, but my old understanding was sort of flawed, I had the CPPFLAGS and LDFLAGS sort of scrambled together, and I was also making an error and assuming the compiler saw /usr/local/lib by default the way it see's /usr/lib by default, etc.  I don't know why I was thinking this, perhaps i've been diving into GNU land a bit too much lately... 

So my understanding now is CPPFLAGS only needs the path to the necessary include files but not the libs path, LDFLAGS/linker only needs the libs path. When the linker see's "-labc" it will go through its lib paths looking for a libabc.a or libabc.so.

I should set both(?) LD_LIBRARY_PATH and LD_LIBRARYN32_PATH to point to where I have my libs located to use them if not already used (such as how all this recent stuff seems to really want to be installed in "/usr/local/lib32").  I am assuming older software used LD_LIBRARY_PATH?  I've only really noticed old software using that, anything somewhat recent I've seen using  LD_LIBRARYN32_PATH..

Here is what I used to successfully compile nettle:

Code:
export CC=/usr/bin/cc
export CXX=/usr/bin/CC
export CFLAGS="-c99 -g0 -woff all -O2 -mips4"
export CXXFLAGS="-g0 -woff all -O2 -mips4"
export CPPFLAGS="-I/usr/local/include -I/usr/nekoware/include"
export LDFLAGS=" -L/usr/local/lib -L/usr/local/lib32 -L/usr/nekoware/lib"

./configure --prefix=/usr/local

I also had to install nettle first and then I was able to run "gmake check"

(09-16-2018, 11:23 AM)mrthinlysliced Wrote: Annd to get nettle tests to run to completion I had to patch it with this:

https://github.com/danielhams/didbs/blob...ixes.patch

Basically the standard C integer header file has guards to stop it being included in C++, but the C++ compiler isn't a new enough version of C++ that it has the "cstdint" header, so we define __c99 to work around that.

thanks for this!  I keep running into that issue once in a while and I just end up declaring those types inline with the code I'm trying to compile.  This sort of sheds some light on it for me.  I'll have to take a closer look at this in the future
(This post was last modified: 09-17-2018, 03:05 PM by gijoe77.)
gijoe77 Online
Tezro

Posts: 349
Threads: 23
Joined: Jun 2018
Find Reply
09-17-2018, 03:00 PM
#7
RE: help with nettle gmake check
LD_LIBRARYN32_PATH is a "more recent" separate env variable to search for "n32" compatible libraries. If everything you are building is 32bit -n32, this is how to specify where libraries can be found at runtime.

(09-17-2018, 03:00 PM)gijoe77 Wrote:
(09-16-2018, 11:23 AM)mrthinlysliced Wrote: Annd to get nettle tests to run to completion I had to patch it with this:

https://github.com/danielhams/didbs/blob...ixes.patch

Basically the standard C integer header file has guards to stop it being included in C++, but the C++ compiler isn't a new enough version of C++ that it has the "cstdint" header, so we define __c99 to work around that.

thanks for this!  I keep running into that issue once in a while and I just end up declaring those types inline with the code I'm trying to compile.  This sort of sheds some light on it for me.  I'll have to take a closer look at this in the future

Strictly speaking I was lazy and did this #define like this because it's just a test class.

The "correct" fix would be to place these #ifdef/#define __c99/#endif (and the undef) _only_ around where the stdint.h is included.

Doing the way I've done it in that patch is a little naughty - there's potential for shenanigins of some c99 things getting defined that the C++ compiler won't like or that conflict with C++ definitions :-)
(This post was last modified: 09-18-2018, 11:02 AM by mrthinlysliced.)
mrthinlysliced Online
Octane

Posts: 71
Threads: 5
Joined: May 2018
Find Reply
09-18-2018, 11:02 AM
#8
RE: help with nettle gmake check
(09-16-2018, 09:53 AM)mrthinlysliced Wrote: For info, if you want to compile "wget" - you can either use the gnutls or openssl libraries - there's an either/or with those two.

I chose openssl as it was less pain (configure wget with "./configure --prefix=INSTALLDIR --with-ssl=openssl".

That reminds me - I ran into an interesting problem on my o2 with compiling openssl.  Seems some parts get compiled 64bit even if I set the the target to irix-mips3-cc and CFLAGS to "-n32".  I've been meaning on circling back on that and figuring out what's doing that, I suspect the Makefile is mucking something up
gijoe77 Online
Tezro

Posts: 349
Threads: 23
Joined: Jun 2018
Find Reply
09-18-2018, 11:09 AM
#9
RE: help with nettle gmake check
(09-18-2018, 11:09 AM)gijoe77 Wrote: That reminds me - I ran into an interesting problem on my o2 with compiling openssl.  Seems some parts get compiled 64bit even if I set the the target to irix-mips3-cc and CFLAGS to "-n32".  I've been meaning on circling back on that and figuring out what's doing that, I suspect the Makefile is mucking something up

https://github.com/danielhams/didbs/blob...ixes.patch

I added an irix-mips4-cc configuration to use c99 and -n32 -mips4.

I don't remember any issues with 64 bit libs, and I've had wget happily link against this (among other things).
mrthinlysliced Online
Octane

Posts: 71
Threads: 5
Joined: May 2018
Find Reply
09-18-2018, 11:20 AM
#10
RE: help with nettle gmake check
(09-18-2018, 11:20 AM)mrthinlysliced Wrote:
(09-18-2018, 11:09 AM)gijoe77 Wrote: That reminds me - I ran into an interesting problem on my o2 with compiling openssl.  Seems some parts get compiled 64bit even if I set the the target to irix-mips3-cc and CFLAGS to "-n32".  I've been meaning on circling back on that and figuring out what's doing that, I suspect the Makefile is mucking something up

https://github.com/danielhams/didbs/blob...ixes.patch

I added an irix-mips4-cc configuration to use c99 and -n32 -mips4.

I don't remember any issues with 64 bit libs, and I've had wget happily link against this (among other things).

oh very awesome!  I'll just give this a go first then - why recreate the wheel right Smile
gijoe77 Online
Tezro

Posts: 349
Threads: 23
Joined: Jun 2018
Find Reply
09-18-2018, 12:34 PM


Forum Jump:


Users browsing this thread: 1 Guest(s)