【问题标题】:Simple makefile for LibElementalLibElemental 的简单生成文件
【发布时间】:2016-10-04 03:40:24
【问题描述】:

我想使用libElemental作为库安装后如下:

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

安装成功并构建示例。我对makefile 的经验有限,但想避免使用cmake,这样我就可以轻松地融入其他地方。

我有一个文件:test.cpp:

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

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

这是我不成功的makefile 尝试:

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

这是我收到的链接器错误的 sn-p:

/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

非常感谢任何帮助我解决此问题的帮助或指示!

【问题讨论】:

  • 试试$(CXX) test.cpp $(CFLAGS) $(LDFLAGS) -o test。但不能保证。
  • would like to avoid using cmake so I can easily integrate elsewhere 但这就是 CMake 的用途。
  • 是的,但我无法控制我目前正在集成的内容,也无法使用 cmake。

标签: c++ makefile cmake mpich


【解决方案1】:

感谢评论者@andar 和@Tsyvarev 指出我的错误是$(LDFlAGS) 的位置。除此之外,只剩下指向 libElemental 安装的动态库的问题。这是最终的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

我也可以跳过添加$(LIB_PATHS),直接设置LD_LIBRARY_PATH

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

注意:由于 libElemental 使用 mpich 而不是 openmpi(如在 makefile 中所见),请使用 mpirun.mpich 而不是仅 mpirun 运行可执行文件,否则您将得到未定义行为。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-14
    • 1970-01-01
    • 1970-01-01
    • 2010-10-18
    • 2021-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多