Question

Have wasted almost full 4 days trying to compile this package. It compiles fine in OSX 10.6, but gives Undefined reference errors when I try to compile it on a linux (Kubuntu 10.04, 3.8.0.27 kernel) machine.

The error seem to be that the makefiles are ordered wrong, but AFAIK, I am the only one having trouble compiling it. So I'm trying to find what's making the difference. The software package is quite big and editing the Makefiles and moving 30-50 libraries here and there doesn't seem like a good idea.

Here's the differences I think I found so far

  • Compiler - gcc-4.7 (Linux) and llvm-gcc-4.2 (OSX)
  • Compiler flags --shared (Linux) and -dynamic -dynamiclib -undefined dynamic_lookup (OSX)

Anyone have any suggestions?

  1. I tried using clang++ and llvm-gcc-4.7 as the compiler, but I think it still used the same linker (ld?). So I could try to specify to use llvm? How do I do that?

  2. is --shared flag somehow different from the dynamic -dynamiclib -undefined dynamic_lookup flags in OSX?

  3. Does the linux kernel or distribution matter? (I think they compiled it fine on a CentOS machine)

Please help. Thanks a lot.

Was it helpful?

Solution

Compiled it with gcc 4.4 and worked flawlessly. I guess the order doesn't matter on 4.4 for the given package.

OTHER TIPS

The undefined references type of errors can be caused by a symbol not being compiled in, not being linked or being linked out of order. The way to debug this is to check the linker line, the symbol that the linker complains about. The error message will probably tell you what object file has the dependency.

Now, you need to find out whether the symbol is compiled or linked, for that you will need to find if it is in any of the object files or in any of the libraries and which. You can use the nm command line tool to list the symbols that are defined in any given .o or library. If the symbol is not there, then you need to figure out what to add to the linker line and that will solve it.

If the symbol appears in one library, then identify which of the libraries depends on that symbol (from the linker error message) and the library that contains it. The former must be listed before the latter in the linker command line (assuming static linking).

As a simple hack, although I recommend against it, you can instruct the gcc linker to do multiple passes by using the --start-group and --end-group command line options. Although I really recommend that you figure out the order of dependencies, as that will also give you a better insight into your project.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top