OpenMP Hello World 错误:“架构 x86_64 的未定义符号:...”
我有以下用于使用 OpenMP 的基本 Hello World 程序:
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<sys/time.h>
#include<omp.h>
int main(int argc, char **argv) {
printf("This line is executed serially.\n\n");
#pragma omp parallel
int nthreads = omp_get_num_threads();
int myid = omp_get_thread_num();
printf("Hello, world! I am thread %d of %d treads\n", myid, nthreads);
return EXIT_SUCCESS;
}
我使用 Microsoft Visual Studio Code 作为 IDE,并且代码是用 c 编写的(因此文件具有 .c,而不是 .cpp 扩展名)。当我在没有调试的情况下运行代码时,VSC 在终端中使用以下命令来运行代码,并出现以下错误:
gcc tescript1.c -o tescript1 && "/[insert_working_directory_here]/"tescript1
Undefined symbols for architecture x86_64:
"_omp_get_num_threads", referenced from:
_main in tescript1-79e487.o
"_omp_get_thread_num", referenced from:
_main in tescript1-79e487.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
其他线程包括 C++ Hello World 体系结构 x86_64 的未定义符号: 似乎表明我使用了错误的编译器。然而,在这个例子中,他们的程序是 c++,而不是 c,并且 VSC 的设置对于如何更改编译器并不明确。我最终陷入困境,无法尝试我读过的建议或 100% 确定问题所在。任何帮助表示赞赏。
I have the following basic Hello World program for using OpenMP:
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<sys/time.h>
#include<omp.h>
int main(int argc, char **argv) {
printf("This line is executed serially.\n\n");
#pragma omp parallel
int nthreads = omp_get_num_threads();
int myid = omp_get_thread_num();
printf("Hello, world! I am thread %d of %d treads\n", myid, nthreads);
return EXIT_SUCCESS;
}
I am using Microsoft Visual Studio Code as an IDE, and the code is written in c (and file therefore has a .c, not .cpp extension). When I run the code without debugging, VSC uses the following command in terminal to run the code, and the following error appears:
gcc tescript1.c -o tescript1 && "/[insert_working_directory_here]/"tescript1
Undefined symbols for architecture x86_64:
"_omp_get_num_threads", referenced from:
_main in tescript1-79e487.o
"_omp_get_thread_num", referenced from:
_main in tescript1-79e487.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Other threads including C++ Hello World Undefined symbols for architecture x86_64: seem to suggest I'm using the wrong compiler. However, in this example, their program is c++, not c, and VSC's settings are anything but clear on how to change compilers. I've ended up stuck without being able to try the suggestions I've read or 100% for sure identify the problem. Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试在 Visual Studio 项目属性中将 /openmp 值设置为 OpenMP 支持,如下所示。
如您所见,我能够在 OpenMP 支持下用 C 语言运行基本的 helloworld 程序。
另外,希望你没有错过,
You could try to set the /openmp value to OpenMP support in Visual studio project properties as shown below.
As you can see I was able to run a basic helloworld program in C with openMP support.
<sys/time.h> is a POSIX header, not part of the C/C++ standard library. It won't work in windows. Use just <time.h> if you are building for windows.
Also, I hope you have not missed,