OpenMPI编译错误
OpenMPI compilation error
我有一些使用OpenMPI的*.cpp文件。此外,我还有*.h文件,其中包含指定给我的函数(其中一些)和它们的实现:
void Show(std::string s);
void ShowLine(std::string s);
void MPI_Output();
所以我在*.cpp文件中使用这些函数,例如:
/*...*/
MPI_Output();
包括这个标题:
#include "my_h.h"
然后我尝试用mpicc
:编译我的蛙图
mpicc -w my_best_program.cpp
它在编译过程中失败,并显示以下消息:
/tmp/icpcBCoxCA.o: In function `main':
MPIDebug9.cpp:(.text+0xa46): undefined reference to `ShowLine(std::string)'
MPIDebug9.cpp:(.text+0xa90): undefined reference to `MPI_Output()'
MPIDebug9.cpp:(.text+0xc0f): undefined reference to `Show(std::string)'
/tmp/icpcBCoxCA.o: In function `info_main(double)':
MPIDebug9.cpp:(.text+0xe49): undefined reference to `Show(std::string)'
/tmp/icpcBCoxCA.o: In function `info(double)':
MPIDebug9.cpp:(.text+0x104e): undefined reference to `ShowLine(std::string)'
此外,一些信息:
mpicc --showme:compile
-I/usr/mpi/intel/openmpi-1.4.4/include -pthread
我的问题有解决办法吗?
您在编译过程中没有遇到问题,但在链接过程中遇到了问题。
mpicc -w my_best_program.cpp my_cpp_file_with_showline.cpp
是你需要的东西。
说明:(简化)
在.h文件中,只有信息"嘿,编译器,有一些方法叫Show
,返回void
,并且想要std::string
类型的参数。当你编译调用这个函数的cpp文件时,请确保它传递了正确的参数,但它会在另一个.cpp文件中提供
它对所有单独的.cpp文件都是一样的(创建.o文件-您的my_best_program.cpp
包含类似于:"有一个info_main(double)
函数,它有一些代码,它需要调用Show(std::string)
-称为未解析引用"
my_cpp_file_with_showline.cpp将使用"There is Show(std::string)
method,that does other something"创建.o。
而且,在链接过程中(目前对您来说是不可见的),所有"未解析的引用"都会被解析——这意味着info_main(double)
将从不同的cpp文件调用Show(std::string)
。
当您使用多个cpp从命令行调用某些C++编译器时,它通常会单独编译它们(每个cpp对另一个cpp一无所知,只是.h文件中的函数声明),然后将所有函数调用和给定函数链接(合并在一起)为可执行文件。
- 用MacOS Mojave编译C++:致命错误:mpi.h:没有这样的文件或目录
- std::is_base_of表示ctor编译错误
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- Qt5:使用QCommandLineParser类时出现奇怪的编译错误
- Qt Cmake 错误编译"GuiSupportQt not found"
- Opengl 精度转换错误编译错误 E0415
- 库将ARM架构错误编译为架构X64
- RT 音频 Mac 错误 g++ 编译错误
- 错误编译Boost.log
- 错误编译QT创建者 / QT窗口小部件示例
- 错误编译MIPS32
- Visual Studio 2013 中的错误(编译和运行代码)
- 链接错误编译qt项目在visual 2010
- 无法用模板错误编译nsgmls
- 奇怪的错误.编译失败
- 如果有人调用c++中的方法,则强制错误(编译时)
- 来自autoconf测试的错误编译命令
- 时间限制超出错误C++编译
- SFML 2.3 和 CodeBlocks 错误编译