timsa7
timsa7

Reputation: 69

gcc compiling linking .a file

in my homework i must use this command to compile my program:

gcc -o mtm_rentals -std=c99 -Wall -pedantic-errors -Werror -DNDEBUG mtm_ex2.c rentals.c list.c -L -lmtm

what i can change in that line are the files im writing after -DNDEBUG. when i do this the gcc says that there are undefined references to specific functions. now those functions are declared in an .h file and are implemented in a given file called libmtm.a i concluded that it doesnt recognize libmtm.a, but our homework task says that the -lmtm flag(which is not declared anywhere) is supposed to link libmtm.a to the program.

what am i missing here? am i supposed to implement somehow the -lmtm flag? thank you!

Upvotes: 0

Views: 5599

Answers (1)

Gunther Piez
Gunther Piez

Reputation: 30419

You are missing a . (single dot) behind the -L.

-lmtm will link against a libmtm library, this is correct. It's not an -lmtm flag, it's a -l flag concatenated with mtm, the library you want to link against. This library is searched in some predefined paths (like /usr/lib/) and additionally in the paths given by -L. Assuming libmtm lives in your current directory, you need to add that to -L, which is done with a ..

Upvotes: 3

Related Questions