Why can't my compiler find my library?

时间:2015-09-01 21:20:55

标签: c gcc static-libraries

I'm trying to compile a simple C program using gcc:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lbryTest.h"

int main(int argc, char *argv[]) {
    double x = 0.0;
    x = lbryTest(2.0, 5.0);
    printf("%f", x);
    printf("Placeholder");
    return 0;
}

lbryTest() is a function that does some simple math operations and returns a double. It is declared in lbryTest.h, and defined in liblbryTest.a.

When I compile the code using

gcc libraryTest.c -l lbryTest

I get the error:

cannot find -llbryTest.

How can I fix this?


Thanks to John Bollinger's comment, it finds the library. I added -L. to the command. This doesn't however answer why it was unable to find the library in the first place. The files are all in the same directory. How can I make it so the library will be found without explicitly adding the path? Or is that unconventional in C, and you should always explicitly add the path to all libraries linked?

0 个答案:

没有答案