gcc compilation and Make file error
I have a directory called "aos" in which i have the results of the make, namely .o file and .a file.
My test case file in a directory called "test1" which is under the "aos" directory.
I am in the test1 directory which has a file called main.c (this is the file I want to execute). I tried compiling the file by giving the comm开发者_如何学Cand
gcc -Wall -pedantic -I ../gtthreads.c -o main main.c ../gtthreads.a
But I get these errors:
../gtthreads.c is not a directory
../gtthreads.a is not a directory
What am i doing wrong here? How do I refer to the .a file and .c files which are in "aos" directory?
The -I
and -L
switches are used to add directories to the #include
and linker search paths respectively. So if you have headers in the parent directory, but include them without relative paths in your code, you can use:
-I..
which will make gcc
look in the parent directory for headers.
If you want to compile main.c
, and gtthreads.c
from the parent directory into an executable, you can:
gcc -Wall -pedantic -I.. ../gthreads.c main.c -o main
If you want to compile main.c
and link it with the gthreads.a
file in the parent directory, just use:
gcc -Wall -pedantic -I.. -o main main.c ../gtthreads.a
精彩评论