This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Newbie compiling -> "undefined reference to" error


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]