Question

I was trying to use ATLAS in my project but I am unable to link even the simplest code with it:

#include <stdio.h>
#include <cblas.h>

void ATL_buildinfo(void);

int main() {
    ATL_buildinfo();
    return 0;
}

I'm compiling with:

gcc -I/home/caian/ATLAS/include/ \
  -I/home/caian/ATLAS/ARCH/include/ \
  -L/home/caian/ATLAS/ARCH/lib/ \
  -latlas main.c -o test

I double-checked the ATL_buildinfo prototype and the libatlas.a, nm shows that ATL_buildinfo is present.

What could be the problem?

Was it helpful?

Solution

Moving the main.c before linker flags may solve it.

$gcc main.c -I..-L...".  

This should solve the problem.

This works because of the way "linking order" is imposed by gnu linker.

The traditional behavior of linkers is to search for external functions from left to right in the libraries specified on the command line. This means that a library containing the definition of a function should appear after any source files or object files which use it. This includes libraries specified with the short-cut -l option, as shown in the following command.

$ gcc -Wall calc.c -lm -o calc   (correct order)

This link explains this behaviour:

http://chara.epfl.ch/~fsalvi/docs/gcc/www.network-theory.co.uk/docs/gccintro/gccintro_17.html

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