0

I would like to use libElemental as a library after installing it as follows:

git clone https://github.com/elemental/Elemental
mkdir build
cd build
cmake ../Elemental
make
make install

Install is successful & examples build. I have limited makefile experience, but would like to avoid using cmake so I can easily integrate elsewhere.

I have one file: test.cpp:

#include <El.hpp>
#include <stdlib.h>

int main(int argc, char* argv[]) {
    return 0;
}

Here is my unsuccessful makefile attempt:

CFLAGS = -O3 -std=gnu++11
LDFLAGS := -lEl
CC = mpicc.mpich2
CXX = mpicxx.mpich2

all: test
test: test.cpp
    $(CXX) $(CFLAGS) $(LDFLAGS) test.cpp -o test

Here is a snippet of the linker errors I receive:

/tmp/ccgDsmEV.o: In function __static_initialization_and_destruction_0': /usr/local/include/El/number_theory/lattice/LLL.hpp:316: undefined reference to El::Timer::Timer(std::string const&)' : : /tmp/ccgDsmEV.o:/usr/local/include/El/number_theory/lattice/LLL.hpp:318: more undefined references to El::Timer::Timer(std::string const&)' follow collect2: error: ld returned 1 exit status make: *** [test] Error 1

Any help or pointers to help me resolve this is much appreciated!

quine
  • 982
  • 1
  • 12
  • 20
  • 1
    Try `$(CXX) test.cpp $(CFLAGS) $(LDFLAGS) -o test`. No guarantees though. – andars Oct 04 '16 at 03:50
  • 1
    Possible duplicate of [How to use LDFLAGS in makefile](http://stackoverflow.com/questions/13249610/how-to-use-ldflags-in-makefile) – Tsyvarev Oct 04 '16 at 06:38
  • 1
    `would like to avoid using cmake so I can easily integrate elsewhere` But that's what CMake is for. – arrowd Oct 04 '16 at 07:27
  • Yes, but I have no control over what I'm integrating with currently and cannot use cmake. – quine Oct 04 '16 at 17:58

1 Answers1

0

Thank you to commenters @andars and @Tsyvarev for pointing out that my error was the placement of $(LDFlAGS). Other than this there just remains the matter of pointing to dynamic libraries installed by libElemental. Here is the final makefile:

CXX=mpicxx.mpich

LIB_PATHS:=-Wl,-rpath,/usr/local/lib/x86_64-linux-gnu:/usr/local/lib
CXXFLAGS:=-std=gnu++11 -O3
LDFLAGS:=-lEl

all: test
test: test.cpp
    $(CXX) $(CXXFLAGS) $(LIB_PATHS) test.cpp -o test $(LDFLAGS)

clean:
    rm -f test

I could also skip adding $(LIB_PATHS) and just set LD_LIBRARY_PATH:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/x86_64-linux-gnu:/usr/local/lib

NOTE: that since libElemental uses mpich instead of openmpi (as seen in the makefile), run executables with mpirun.mpich instead of just mpirun or you'll get undefined behavior.

quine
  • 982
  • 1
  • 12
  • 20