6 Replies - 33467 Views - Last Post: 18 June 2007 - 02:27 PM Rate Topic: -----

#1 Vegter  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 77
  • Joined: 21-September 05

How to use External functions?

Posted 22 October 2005 - 04:49 AM

Hi

I'm unsure how to use functions that are declared as extern... I assume these are built-in functions in C that I can simply reference? But how do I do that?

Say, for example I want to use the built-in incomplete gamma function, that is
extern double igamc (double a, double x);



But I simply get a undefined reference compilation error: "Undefined reference to 'igamc'"
I've seen people use these functions, there are a whole list of them.

Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: How to use External functions?

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: How to use External functions?

Posted 22 October 2005 - 08:36 AM

extern is a keyword the indicates the function (or variables) may be compiled as part of a separate module...have you included the correct libraries, or at least defined the function yourself?
Was This Post Helpful? 0
  • +
  • -

#3 Vegter  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 77
  • Joined: 21-September 05

Re: How to use External functions?

Posted 22 October 2005 - 10:50 AM

Ok, so the example program I was looking at was using the Cephes Maths library (I didn't realize it at the time and I thought it was built in). Anyone know how to correctly link the Cephes library into your program? The library can be found here.
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: How to use External functions?

Posted 22 October 2005 - 01:48 PM

You'll have to download it and install the libraries on your development machine...it comes with an installation guide, I believe...at the very least, there should be makefiles.
Was This Post Helpful? 0
  • +
  • -

#5 Vegter  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 77
  • Joined: 21-September 05

Re: How to use External functions?

Posted 22 October 2005 - 02:00 PM

Quote

You'll have to download it and install the libraries on your development machine...it comes with an installation guide, I believe...at the very least, there should be makefiles.


Thank you for the reply. I did download it, and it does come with an installation guide. Problem is, the whole package is 5 meg, and I only want to use 4 functions in total. So obvioustly I don't want to include the whole package in my project. That means if I look under the 'double' directory (because that's the precision I want), and I would like to use the igam.c file. But I can't seem to figure out exactly what other files and functions I need to link to get it working... I get a few 'function not found' and a few 'conflicting types' declarations when I try and compile the file. Maybe someone here has used this library (because it looks really well-written and very useful).

So here's what I did...
I copied the igam.c file from the 'double' directory to a new directory. I copied the 'mconf.h' file from the home directory to this new directory. The installation guide (which is only like 15 lines btw) says every subdirectory contains a file called 'protos.h' which I will need). But the 'double' subdirectory doesn't contain such a file! If I compile the igam.c file without it, I get a lot of errors. So I include the "mconf.h" file and <math.h> and compile it using

gcc igam.c -lm -o Test

and then I get
'undefined reference to lgam'
'undefined reference to MAXLOG'
'undefined reference to mtherr'
'undefined reference to MACHEP'

If someone can help me with this, I will be forever grateful.
Was This Post Helpful? 0
  • +
  • -

#6 hwadhar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-June 07

Re: How to use External functions?

Posted 18 June 2007 - 08:50 AM

Did you ever resolve this? I am having the same issue.
Was This Post Helpful? 0
  • +
  • -

#7 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5348
  • View blog
  • Posts: 27,305
  • Joined: 10-May 07

Re: How to use External functions?

Posted 18 June 2007 - 02:27 PM

Can you post all of your code? Or at least everything prior to main
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1