13 Replies - 3843 Views - Last Post: 27 June 2011 - 04:05 PM Rate Topic: -----

#1 xTorvos  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 60
  • View blog
  • Posts: 271
  • Joined: 23-October 09

How to Use Libraries?

Posted 25 June 2011 - 08:23 AM

Hello,

I've always wrote my own header files (maximum of 2) and programs from scratch in classes. Now that I'm doing research, I need to use someone else's libraries for cryptography. I've downloaded the code, but I don't really understand how I'm supposed to use it. If anyone is interested, I'm trying to work with the libecc library located here.

Anyway, I'd really like someone to point me in the direction of a tutorial or just give me some advice on how to incorporate someone else's code (such as libecc) into my own.

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: How to Use Libraries?

#2 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: How to Use Libraries?

Posted 25 June 2011 - 08:27 AM

Which compiler? The process is different depending on your compiler (and sometimes IDE).
Was This Post Helpful? 0
  • +
  • -

#3 xTorvos  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 60
  • View blog
  • Posts: 271
  • Joined: 23-October 09

Re: How to Use Libraries?

Posted 25 June 2011 - 08:30 AM

I'll be using Vim and GCC
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5662
  • View blog
  • Posts: 22,505
  • Joined: 23-August 08

Re: How to Use Libraries?

Posted 25 June 2011 - 08:56 AM

Assuming the name of the library is libecc.a, you will use a command line like

g++ -ggdb3 -Wall -pedantic -o myprog myprog.cpp -L/path/to/directory/containing/libecc.a -lecc


The manual on this
Was This Post Helpful? 1
  • +
  • -

#5 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2209
  • View blog
  • Posts: 9,183
  • Joined: 18-February 07

Re: How to Use Libraries?

Posted 25 June 2011 - 09:07 AM

While there might be a couple of generalities the actual process changes from library to library.

The two BIG points are: a. Tell the compiler where the include files are, b. tell the compiler/linker where the libraries are (and tell the compiler/linker which ones you need).

So for libecc it looks like you run
./configure
make
make install

and it will put the includes and libs in /usr/local directory and (I am not a linux/unix guy) I think that should already be setup with your compiler so you should just have to add a -lecc

I could be wrong (alas I am on windows so...)
Was This Post Helpful? 1
  • +
  • -

#6 xTorvos  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 60
  • View blog
  • Posts: 271
  • Joined: 23-October 09

Re: How to Use Libraries?

Posted 25 June 2011 - 09:37 AM

Thanks for the help so far. I'll see how far this gets me and let you know if I run into issues.
Was This Post Helpful? 0
  • +
  • -

#7 xTorvos  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 60
  • View blog
  • Posts: 271
  • Joined: 23-October 09

Re: How to Use Libraries?

Posted 25 June 2011 - 12:04 PM

I ran './configure' in the directory, but after that 'make' and 'make install' wouldn't work. In addition to that, 'locate ecc.a' returned nothing.

Any ideas?
Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5662
  • View blog
  • Posts: 22,505
  • Joined: 23-August 08

Re: How to Use Libraries?

Posted 25 June 2011 - 12:07 PM

No errors on configure or make? You didn't perhaps get this error on configure?

configure: error: 
* Cannot find -lgmpxx (see config.log for more info), did you configure gmp with --enable-cxx?
* You need gmp version 4.1 or higher (rpm: gmp-4.1 and gmp-devel-4.1), see http://swox.com/gmp/.

Was This Post Helpful? 0
  • +
  • -

#9 xTorvos  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 60
  • View blog
  • Posts: 271
  • Joined: 23-October 09

Re: How to Use Libraries?

Posted 25 June 2011 - 12:31 PM

Nice catch. I just saw that it ended and assumed all was well. :stupid:

Any ideas on how I can fix that?
Was This Post Helpful? 0
  • +
  • -

#10 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5662
  • View blog
  • Posts: 22,505
  • Joined: 23-August 08

Re: How to Use Libraries?

Posted 25 June 2011 - 12:33 PM

I would hazard to say that you need to acquire libgmp and compile it with the noted flag, --enable-cxx. But that's just a guess from reading the error!
Was This Post Helpful? 2
  • +
  • -

#11 xTorvos  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 60
  • View blog
  • Posts: 271
  • Joined: 23-October 09

Re: How to Use Libraries?

Posted 25 June 2011 - 12:53 PM

Right.

I have these currently on my computer:
/usr/lib/libgmp.so.3
/usr/lib/libgmp.so.3.5.2
/usr/lib/libgmpxx.so.4
/usr/lib/libgmpxx.so.4.1.2
/usr/lib/ssl/engines/libgmp.so
/usr/lib32/ssl/engines/libgmp.so



I'm assuming it's not one of these, nor is it apt-getable.

So I decided to go to the website, download it, and try the same thing that I did with this (run './configure').

Now I'm in the same boat with:
checking for suitable m4... configure: error: No usable m4 in $PATH or /usr/5bin (see config.log for reasons).


I'm just wondering if this is going to be an endless string of missing dependencies.

This post has been edited by xTorvos: 25 June 2011 - 12:56 PM

Was This Post Helpful? 0
  • +
  • -

#12 xTorvos  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 60
  • View blog
  • Posts: 271
  • Joined: 23-October 09

Re: How to Use Libraries?

Posted 26 June 2011 - 10:31 AM

Is it necessary to use ./configure and make? Can't I just move the directories with the header files to where I'm developing? I tried doing this and got errors, but shouldn't this be possible?
Was This Post Helpful? 0
  • +
  • -

#13 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2209
  • View blog
  • Posts: 9,183
  • Joined: 18-February 07

Re: How to Use Libraries?

Posted 26 June 2011 - 02:45 PM

That is only possible in the case of "header only libraries" and this is not one.

Think about how compiling works:

the preprocessor takes a .c file and several .h files and pastes them all together and feeds them to the compiler. The compiler generates an .o (or .obj on windows -- an object file) and passes it on the the linker. The liker takes the .o file(s) and extracts the "object code" which it links together with other object files and libraries (.a or .lib) to produce the final output executable.

So -- headers tell the compiler how to call functions that has object code (compiled code) stored in an object file or a library. So just having the header file does not give the linker the object code it needs. So while you will be able to compile, you will not be able to link.

the ./configure will customize the make files (and other files) for your environment, and the make will compile the source code to object files and then put the object files into libraries.


So yes you do need these steps. UNLESS you can find a pre-compiled version of the library compatible with your compiler (which actually can be very hard which is why the ./configure is required in the first place).


What environment are you using?
Was This Post Helpful? 2
  • +
  • -

#14 xTorvos  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 60
  • View blog
  • Posts: 271
  • Joined: 23-October 09

Re: How to Use Libraries?

Posted 27 June 2011 - 04:05 PM

Thanks for the quick lesson. :)

I'm running Ubuntu 11.04 x64 and using the gcc/g++ compiler. If that's not what you meant then please elaborate.

Thanks again!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1