LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-12-2011, 02:07 PM   #1
Kanangill
LQ Newbie
 
Registered: Jan 2011
Posts: 5

Rep: Reputation: 0
Unhappy Does one 'compile' APIs?


Probably a stupid sounding question, but bear with me please. I need to use the link grammar parser in order to do some part of speech tagging. It's freely available and works once you run the makefile or 'make' it or however it's correctly said.
Thing is, it has a C API which I intend to use. And once I ran a bit of the sample code given in the documentation it gave a whole host of errors. This is very confusing because I'm including the path for the folder that has all the header files.

gcc -I/path/include/ filename.c

But it still gives me errors about not being able to find things that are clearly defined there.

An hour of trudging around the internet tells me I need to 'compile' the API first. I'm not exactly sure how or if I'm supposed to do that. If someone could just shed light on this it would be greatly appreciated. I grow increasingly cynical to the musical swell of my tiny brain rattling in my skull.
 
Old 05-12-2011, 02:37 PM   #2
Hidden Windshield
Member
 
Registered: Jul 2010
Distribution: Fedora
Posts: 68

Rep: Reputation: 27
The quick answer is that you don't compile an API, you compile a particular implementation of an API.

An API is basically a simple language used to send commands to, and receive responses from, another piece of code. An implementation is a piece of code that actually does what your code tells it to do.

If you need more help, you'll need to explain exactly what you did. Where did you extract it? What commands did you run? What is the exact error message?
 
Old 05-12-2011, 02:42 PM   #3
jthill
Member
 
Registered: Mar 2010
Distribution: Arch
Posts: 211

Rep: Reputation: 67
An API is a description of how code works when you invoke it. Including headers in your code makes your code use the other code properly. But you have to supply the other code. It's just code.

You don't say what errors you're getting, but I bet if you add the '-c' option it runs that far with no errors. That'll mean that your code is compiling correctly, but since your system doesn't supply the other code now you have to compile it someplace and link it with your own code. Compiling your code made a .o file. The most brutal method of linking all the necessary bits together is to name all the necessary .o files, like 'gcc filename.o this.o that.o whathaveyou.o -o myproggy'. That'll do to start with, you'll want to read up on libraries eventually, there's lots of ways to vary the scheme to make it more convenient or efficient in different circumstances.
 
Old 05-12-2011, 11:37 PM   #4
Kanangill
LQ Newbie
 
Registered: Jan 2011
Posts: 5

Original Poster
Rep: Reputation: 0
Smile

Hey wow, thanks for getting back to me so quickly. This compiling bit just didn't strike me because, for example, I just used WordNets API just out of the box. I mean I just had to give the g++ options for the include path and also the path to their library while compiling.

The exact errors I'm getting are is that the data structures that are declared in the headers that I'm including are not recognised. That is errors like 'xx is not declared, First use this function.' Thing is, it is declared right there in header.

I'm sorry if I'm a little slow to understand this. So you're suggesting that I compile all the headers into object files?

Also exactly what I did was, extract the packages in my home dir. Then I ran the make file. So then the command line interface to the parser works. (Which is just accessed by ./parse) Could you also elaborate on on what you meant by implementation of the API
 
Old 05-13-2011, 04:08 AM   #5
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Rep: Reputation: 111Reputation: 111
It may help if you paste the exact error messages.
 
Old 05-13-2011, 09:46 AM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
The term API is an acronym that we use when we want to describe the format, syntax or idioms used by some library or other callable system. Its embodiment in the C language is principally in the C headers. This is the classic use of C header files; to describe the interface that we use to access a package.
In use, we include appropriate headers, which the compiler uses to know what we mean when it sees the various tokens that compromise the API. The compiler needs to know how to find the header files that we identify, at compile time. In gcc, there is the option "-I", (uppercase eye) with its associated value that is a filesystem path that the compiler searches when it needs to find a header file. Failing to find a specified header will result in a compile-time error. Do you get any such error? There may be conditionals in the headers which need to be set with appropriate #defines. Failing to set these appropriately (should be documented, or something like 'configure' should have set it up correctly) could result in the compiler finding and reading the headers, but not compiling the right parts. Is your application intended to build or run in a specific architecture?
Similarly, at link time, gcc needs to know what libraries to link. These are the libraries that implement the API, and gcc uses the somewhat quirky syntax of the '-l' (lowercase ell), followed immediately by the name of a library, but with the library name's 'lib' prefix removed. Analogous to the '-I' option, the '-L' option is used to supply a filesystem path where the linker should look to find any of the specified or default libraries. Two possible error can arise at link time: unresolved symbols from failing to specify the appropriate library or libraries, or the linker failing to find a specified library, caused by the absence of the appropriate '-L' switch. Do you see link-time errors like that? A third possible error case exists: failing to find a specified shared object library at runtime. This usually won't occur unless the runtime binary is moved to another host, or if the library is moved or deleted.
In addition to posting your error message(s), it is probably also helpful to post the commandline(s) that evoked the message(s).

--- rod.

Last edited by theNbomr; 05-13-2011 at 09:51 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ APIs manolakis Programming 5 08-28-2007 03:34 PM
Creating APIs blackhock Programming 4 06-15-2006 03:34 PM
BASE64 APIs? EddyHahn Programming 0 11-29-2004 09:59 PM
APIs elitecodex Programming 14 03-04-2004 04:48 PM
equivalent to these APIs meshmesh Linux - Software 2 12-31-2003 03:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration