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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux