marekandreas / elpa

A scalable eigensolver for dense, symmetric (hermitian) matrices (fork of https://gitlab.mpcdf.mpg.de/elpa/elpa.git)
Other
25 stars 11 forks source link

C++ "multiple definition of" issue #30

Closed toxa81 closed 1 year ago

toxa81 commented 1 year ago

Hi @marekandreas ! It is probably an issue with the header guards. To reproduce: a.cpp:

#include <elpa/elpa.h>

int main()
{
    return 0;
}

b.cpp:

#include <elpa/elpa.h>

void foo()
{

}

gcc a.cpp b.cpp -I/path/to/elpa/include/elpa_openmp-2022.11.001.rc2/ -L/path/to/elpa/elpa/lib -lelpa_openmp leads to

/usr/bin/ld: /tmp/ccK00fbG.o: in function `elpa_set(elpa_struct*, char const*, int, int*)':
b.cpp:(.text+0x0): multiple definition of `elpa_set(elpa_struct*, char const*, int, int*)'; /tmp/cc51CaRG.o:a.cpp:(.text+0x0): first defined here
/usr/bin/ld: /tmp/ccK00fbG.o: in function `elpa_set(elpa_struct*, char const*, double, int*)':
b.cpp:(.text+0x35): multiple definition of `elpa_set(elpa_struct*, char const*, double, int*)'; /tmp/cc51CaRG.o:a.cpp:(.text+0x35): first defined here
/usr/bin/ld: /tmp/ccK00fbG.o: in function `elpa_get(elpa_struct*, char const*, int*, int*)':
b.cpp:(.text+0x75): multiple definition of `elpa_get(elpa_struct*, char const*, int*, int*)'; /tmp/cc51CaRG.o:a.cpp:(.text+0x75): first defined here
/usr/bin/ld: /tmp/ccK00fbG.o: in function `elpa_get(elpa_struct*, char const*, double*, int*)':
b.cpp:(.text+0xac): multiple definition of `elpa_get(elpa_struct*, char const*, double*, int*)'; /tmp/cc51CaRG.o
...
toxa81 commented 1 year ago

A quick fix can be to make all functions defined in the header files to be inline. Or move them to *.c files and keep only declaration in the headers.

marekandreas commented 1 year ago

Dear @toxa81,

has been fixed, and as soon as the CI pipeline is through it will be released with the 2022.11.001 release