This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Newbie compiling -> "undefined reference to" error
- From: "John (Eljay) Love-Jensen" <eljay at adobe dot com>
- To: Javier García <tirengarfio at hotmail dot com>, <gcc-help at gcc dot gnu dot org>
- Date: Thu, 9 Aug 2007 09:08:59 -0700
- Subject: RE: Newbie compiling -> "undefined reference to" error
- References: <BAY123-F25F357F9F733C9DCF5533ABFE00@phx.gbl>
Hi Javier,
>if I have a lot of .cpp files like Prueba.cpp ("it is so hard to include them on the compiling command..."), Is there any other way to compile the main file?
You can compile each C++ source (.cpp) into its own object file (.o), using "g++ -c" toolchain driver.
You can collate sets of object files (.o) into archives (.a), using the "ar" tool.
Assuming your archives are called uno.a dos.a and tres.a, you can link by:
g++ -c main.cpp -o main.o
g++ main.o uno.a dos.a tres.a -o main
The caveat is that archives should appear in dependency order. If uno.a depends on things appearing in dos.a, everything is good.
If dos.a depends on things appearing in uno.a, that could be bad since the linker only includes symbols from the archives that fulfill outstanding symbols, and it does it in one pass.
If uno.a and dos.a have cyclical dependency (very bad, but sometimes it happens), you may need to do something heinous like...
g++ main.o uno.a dos.a uno.a tres.a -o main
HTH,
--Eljay