Hello guys,
i've a little problem with gcc.
I've created two project with eclipse, and the first project is used to compile the second.
I try to compile with the command:
gcc -I /prog1/src/ -L /prog1/src -o main main.c
I would guess that prog1/src contains some dependent files containing
code which is needed by main.c.
The above command line provides the search paths for include files
with -I so that the compilation (just up to the linking stage) can succeed:
main.c is able to find the #include files.
The command line also provides the library search path with -L. However,
final linking to make the main executable will stil fail because a library
search path is not enough to bring in the dependent code. Libraries also have
to be specified on the compiler command line. Source files do not specify
which libraries they need to link with. (There is no such thing in the standrad
C language, though some systems, like Microsoft's compiler, have an extension
for expressing, in a C source file, what library it needs.)
If the source files under prog1/src have been linked to form library, such
as for example "libprog1.a", then you can just add "-lprog1" to the
command line. The argument -l<name> will cause the toolchain to look for
a library called "lib<name>.a", and one of the places in which it will
look is the directory specified by -L.
gcc -I /prog1/src/ -L /prog1/src -o main main.c -lprog1
If prog1/src contains only object files, then the -L argument is useless.
You have to bring all those object files into the command line:
gcc -I /prog1/src/ -o main main.c prog1/src/foo.o prog1/src/bar.o ...
It may be possible to use a wildcard:
gcc -I /prog1/src/ -o main main.c prog1/src/*.o
but that's rather playing it loose. What if not all the .o files are
needed by main.c. Also, what if some are missing (havent' bee compiled?).
"File prog1/src/foo.o not found" is a better diagnostic than unresolved symbols.
Anyway, since you're using Eclipse, maybe Eclipse has a way to handle
dependent projects? Why use an interactive development environment,
but link programs with manual command lines?