help getting started (on Linux)

I apologize if this is not the best place for this, but I could use some help getting started. I’ve created a super-simple test program and cannot link.

Here’s what I did:

  1. dowloaded the latest DOM (patch 3) and docs zip files from SourceForge.
  2. unzipped, changed directory to COLLADA_DOM.
  3. make - this built with no errors
  4. copied libraries in lib-dbg (*.a) to the directory of my test program.
  5. attempted to build test program with collada libraries…
    Result: undefined reference to `DAE::DAE()’

Here’s my program: collada_test.cpp


#include <stdio.h>
#include “dae.h” // Collada API includes
#include “dom/domCOLLADA.h”

int main(int argc, char *argv)
{
int ret;

// Instantiate the DAE object for the input file
DAE *input = new DAE;

// Load the COLLADA file
ret = input->load(argv[1]);
if (ret != DAE_OK)
{
	fprintf(stderr, "load failed

");
exit(-1);
}

return 0;

}


Here’s my build command with verbose output:


g++ -v -Wall -I…/COLLADA_DOM/include/ -I…/COLLADA_DOM/include/1.4/ ./*.a collada_test.cpp
Using built-in specs.
Target: i486-linux-gnu
Configured with: …/src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.0 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-awt=gtk-default --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr --disable-werror --with-tune=i686 --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.4 20060507 (prerelease) (Debian 4.0.3-3)
/usr/lib/gcc/i486-linux-gnu/4.0.4/cc1plus -quiet -v -I…/COLLADA_DOM/include/ -I…/COLLADA_DOM/include/1.4/ -D_GNU_SOURCE collada_test.cpp -quiet -dumpbase collada_test.cpp -mtune=i686 -auxbase collada_test -Wall -version -o /tmp/ccusHzSR.s
ignoring nonexistent directory “/usr/local/include/i486-linux-gnu”
ignoring nonexistent directory “/usr/include/i486-linux-gnu”
#include “…” search starts here:
#include <…> search starts here:
…/COLLADA_DOM/include/
…/COLLADA_DOM/include/1.4/
/usr/lib/gcc/i486-linux-gnu/4.0.4/…/…/…/…/include/c++/4.0.4
/usr/lib/gcc/i486-linux-gnu/4.0.4/…/…/…/…/include/c++/4.0.4/i486-linux-gnu
/usr/lib/gcc/i486-linux-gnu/4.0.4/…/…/…/…/include/c++/4.0.4/backward
/usr/local/include
/usr/lib/gcc/i486-linux-gnu/4.0.4/include
/usr/include
End of search list.
GNU C++ version 4.0.4 20060507 (prerelease) (Debian 4.0.3-3) (i486-linux-gnu)
compiled by GNU C version 4.0.4 20060507 (prerelease) (Debian 4.0.3-3).
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=32093
as -V -Qy --32 -o /tmp/cczilXZO.o /tmp/ccusHzSR.s
GNU assembler version 2.16.91 (i486-linux-gnu) using BFD version 2.16.91 20060413 Debian GNU/Linux
/usr/lib/gcc/i486-linux-gnu/4.0.4/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/gcc/i486-linux-gnu/4.0.4/…/…/…/…/lib/crt1.o /usr/lib/gcc/i486-linux-gnu/4.0.4/…/…/…/…/lib/crti.o /usr/lib/gcc/i486-linux-gnu/4.0.4/crtbegin.o -L/usr/lib/gcc/i486-linux-gnu/4.0.4 -L/usr/lib/gcc/i486-linux-gnu/4.0.4 -L/usr/lib/gcc/i486-linux-gnu/4.0.4/…/…/…/…/lib -L/usr/lib/gcc/i486-linux-gnu/4.0.4/…/…/… -L/lib/…/lib -L/usr/lib/…/lib ./libcollada_dae.a ./libcollada_dom.a ./libcollada_LIBXMLPlugin.a ./libcollada_stdErrPlugin.a ./libcollada_STLDatabase.a /tmp/cczilXZO.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/i486-linux-gnu/4.0.4/crtend.o /usr/lib/gcc/i486-linux-gnu/4.0.4/…/…/…/…/lib/crtn.o
/tmp/cczilXZO.o: In function main': collada_test.cpp:(.text+0x33): undefined reference to DAE::DAE()’
collect2: ld returned 1 exit status


Am I doing something silly? How can the collada libs be built and linked and not define DAE?

I’m rusty with my g++ knowledge, but don’t you need -l to actually link in a library?

No. Using -l is a standard way to do it because it automatically searches linker environment paths. Using this build command instead…

g++ -v -Wall -I…/COLLADA_DOM/include/ -I…/COLLADA_DOM/include/1.4/ -L. -lcollada_dae -lcollada_dom -lcollada_LIBXMLPlugin -lcollada_stdErrPlugin -lcollada_STLDatabase collada_test.cpp

…I get the same result: undefined reference to `DAE::DAE()'.

In the verbose printout you can see that the collect2 (link) command is getting the collada libs.
Surely someone out there is using COLLADA_DOM on Linux with GCC?

Another thing to try: specify the libraries after the source files that depend on them.

That did it. I don’t know why I didn’t know that, but thanks! I can build now.

That’s just how gcc/g++ work apparently. See this for example: “The last point has to do with the fact that gcc processes the files listed on the command line in sequence and will only resolve references to libraries if they are given after the file that makes the reference.”

Search order prerequisites are needed with static linking . People are forgetting that since dynamic linking is so prevalent.