quine quine - 1 year ago 94
C++ Question

Simple makefile for LibElemental

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 install

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

I have one file:

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

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

Here is my unsuccessful

CFLAGS = -O3 -std=gnu++11
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!

Answer Source

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:


CXXFLAGS:=-std=gnu++11 -O3

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

    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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download