LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Does one 'compile' APIs? (https://www.linuxquestions.org/questions/programming-9/does-one-compile-apis-880375/)

Kanangill 05-12-2011 02:07 PM

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.

Hidden Windshield 05-12-2011 02:37 PM

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?

jthill 05-12-2011 02:42 PM

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.

Kanangill 05-12-2011 11:37 PM

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

Ramurd 05-13-2011 04:08 AM

It may help if you paste the exact error messages.

theNbomr 05-13-2011 09:46 AM

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.


All times are GMT -5. The time now is 08:05 AM.