Search code examples
cdrmaa

DRMAA- Cant' link drmaa library when compiling c file


I wrote a small c file to test DRMAA but it keeps telling me that the DRMAA functions I used are not defined. I included the drmaa.h file in the C code. When I use -idrmaa I get this error:

[mkatouzi@argo-1 ~]$ cc -o drmtest -I$SGE_ROOT/include/ -ldrmaa -ldl drmtest.c
/usr/bin/ld: cannot find -ldrmaa

the DRMAA header file is in this path: $SGE_ROOT/include/

If I compile the file without -ldrmaa I get this error:

[mkatouzi@argo-1 ~]$ cc -o drmtest -I$SGE_ROOT/include/  drmtest.c
/tmp/cclsPr9O.o: In function `main':
drmtest.c:(.text+0x3c): undefined reference to `drmaa_init'
drmtest.c:(.text+0x83): undefined reference to `drmaa_exit'
collect2: ld returned 1 exit status

I am using my school's UNIX system and I am very new to it. Can anyone help me with this?

This is my drmtest.c file:

#include <stdio.h>
#include "drmaa.h"


int main (int argc, char **argv) {


char error[DRMAA_ERROR_STRING_BUFFER];
int errnum = 0;
errnum = drmaa_init (argv[0], error, DRMAA_ERROR_STRING_BUFFER);
if (errnum != DRMAA_ERRNO_SUCCESS) {
    fprintf (stderr, "Couldn't init DRMAA library: %s\n", error);
return 1; }
/* Do Stuff */
errnum = drmaa_exit (error, DRMAA_ERROR_STRING_BUFFER);
if (errnum != DRMAA_ERRNO_SUCCESS) {
    fprintf (stderr, "Couldn't exit DRMAA library: %s\n", error); 
return 1; }
return 0;
}

Solution

  • In the first case, the linker is you telling it does not know where to find the drmaa library. In the second case, since you have not included the drmaa library, the linker is telling you it does not know how to resolve the drmaa functions you are using.

    You need to figure out where the drmaa library files are, i.e. in which directory.

    Once you know that, you can specify -L/path/to/drmaa/directory when compiling/linking to resolve the problem.

    As per Brian Cain's answer, the library (drmaa.a or drmaa.so) is probably under $SGE_ROOT/lib.

    Finally, since the directory where the library is stored is not in the system's standard library search path, you have to tell the dynamic linker where to find the library when running the executable. There are two ways to achieve this:

    • Set (and export) the LD_LIBRARY_PATH environment variable to the library's directory (e.g. $SGE_ROOT/lib)

    • Or add the -R/path/to/drmaa/directory option when compiling/linking.