使用 mpicc 编译非 mpi 库

标签 c mpi mpich

我想用我自己的库编译 mpi。我不确定适用于 gcc 的选项(例如 -I/-L/)是否适用于 mpicc。

我尝试使用以下选项进行编译,但出现以下错误。

mpicc -I$(CURRENT_DIR)/util -I$(CURRENT_DIR) -L$(CURRENT_DIR)/util -o server server.c
mpicc -I./util -I. -L./util -o server server.c
/tmp/ccA5be6Z.o: En la función `main':
server.c:(.text+0x195): undefined reference to `list_create'
server.c:(.text+0x219): undefined reference to `list_add'
server.c:(.text+0x228): undefined reference to `list_count'
collect2: error: ld returned 1 exit status

这些是我的 server.c 包含

#include <mpi.h>
#include <list.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>

这是我的 pwd/util 文件夹

$ ls
list.c list.h list.o
...

最佳答案

mpicc(以及其他 MPI 构建命令)只是编译器之上的包装器。因此,如果您使用 gcc,则所有 gcc 选项和指令都可用。

关于 OpenMPI,您可以使用 --showme 选项展示编译器和使用的选项。您可以在 OpenMPI 常见问题解答 ( https://www.open-mpi.org/faq/?category=mpi-apps#wrapper-showme-with-no-file ) 中查看详细信息。 MPICH ( https://www.mpich.org/static/docs/v3.2.x/www1/mpicc.html ) 中提供了类似的选项

您的问题与 MPI 无关。您只是缺少在链接步骤中添加一些对象(可能是 list.o)。您应该考虑创建一个 Makefile 以简化构建过程。

关于使用 mpicc 编译非 mpi 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55761756/

相关文章:

mpi - 为什么 MPI_Barrier 对于跨不同节点的工作人员不会同时停止?

c++ - pmpi_gather 中的 fatal error

compilation - 找不到mpif.h编译错误?

c - 用 g_unix_signal_add 添加后不调用中断句柄

c - 什么时候使用枚举?

java - 在不使用 JNI 的情况下从 Java 调用 native 函数(使用堆栈操作)

scheduled-tasks - MPI 任务调度

python - 当内部和内部通信器合并时,使用 Spawn() 从 python 生成的 Fortran 子进程(或 C++ 或 python)不会断开连接

mpi - 建议使用 Benchmark 程序来比较 MPICH 和 OpenMPI

c - 通过中断保护读取值