1

I'm trying to compile my C code but I need to tell the GCC compiler where two file are.

The two files are located here

/usr/local/ssl/include/
/usr/local/ssl/lib/

I want to add this to my gcc -o file file.c so that my program can work.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Kevin Jones
  • 419
  • 1
  • 6
  • 21
  • To provide a search path for include files use the `-I` option, to provide a search path for libraries to link in use the `-L` option – yano Oct 24 '17 at 21:14
  • like -I and -L – Kevin Jones Oct 24 '17 at 21:17
  • Try using `man gcc` – Mayank Verma Oct 24 '17 at 21:20
  • 1
    path to include directory,, try `gcc -I/usr/local/ssl/include -L/usr/local/ssl/lib -o file file.c` .. I'm not super positive about the order which is why I'm not answering,, but those are the right options for adding a search directory for include files and a search directory for static linking at least. – yano Oct 24 '17 at 21:20
  • it worked, I dont think the order matter, if you want you can put it in the answer to I can checkmark it – Kevin Jones Oct 24 '17 at 21:25
  • hmmm, order _does_ matter for linking (although perhaps not for search directories, not sure) .. just curious.. does it fully compile if you try `gcc -I/usr/local/ssl/include -o file file.c`. You're not explicitly linking in any libraries, maybe you don't need that. – yano Oct 24 '17 at 21:32
  • that complies as well – Kevin Jones Oct 24 '17 at 21:34

1 Answers1

2

In gcc, the -I option is used for adding a directory to the set of directories to search for header files, and the -L option is used for adding a directory to the set of directories to search for libraries. Since you're not explicitly linking in any libraries, you shouldn't need the -L option in this case.

gcc -I/usr/local/ssl/include -o file file.c

If you were linking in libraries, something like the following format should work, assuming that file.c calls a function in libmyLib.a:

gcc -I/usr/local/ssl/include -o file file.c -L/path/to/my/library -lmyLib

See this question for more details regarding library linking order.

yano
  • 4,827
  • 2
  • 23
  • 35