提问人:Zuddas98 提问时间:11/18/2022 更新时间:11/18/2022 访问量:51
mpicxx 链接器未将对象与可执行文件链接:未定义的体系结构x86_64符号:“_main”错误
mpicxx linker doesn't link object with an executable : Undefined symbols for architecture x86_64: "_main" error
问:
我创建了一个测试程序Demo_00.cpp,其中包含以下代码:
#include <stdio.h>
int main(int argc, char** argv){
printf("Hello world! \n");
}
我制作了目标文件
mpicxx -c -o Demo_00.o Demo_00.cpp
但是当我尝试通过以下命令将 Demo_00.o 链接到 Demo_00.exe:
mpicxx -o Demo_00.exe Demo_00.o -v
我收到以下错误:
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: x86_64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch x86_64 -platform_version macos 13.0.0 13.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o Demo_00.exe -L/usr/local/Cellar/open-mpi/4.1.4_2/lib -L/usr/local/opt/libevent/lib -L/usr/local/lib Demo_00.o -lmpi -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
通过 brew 重新安装了 MPICH,使用了 g++ 编译器,但它们都返回了相同的问题。删除了我设备上的所有其他 MPICH 安装(包括 ~/sfw/MPICH),同样的问题。
运行了指定 mpicxx 确切路径的命令,但遇到了同样的问题。/usr/local/bin/mpicxx -o Demo_00.exe Demo_00.o
答: 暂无答案
评论
nm Demo_00.o | grep main
.exe
warning: nm: no name list