gpt4 book ai didi

c++ - 在配置了 g++ 和 gcc 的 netbeans 中使用 -fopenmp 编译

转载 作者:行者123 更新时间:2023-11-30 03:35:21 24 4
gpt4 key购买 nike

我正在尝试配置我的 netbeans 以处理我的并行编程 C++ 代码。我可以使用命令行 (cygwin) 编译该代码,但现在为了进一步调试和编码更复杂的东西,我想转移到某个 IDE 并选择 neatbeans 来完成我的任务。一旦我在 netbeans 中单击构建我的应用程序按钮,有人可以建议我如何添加 -fopenmp 来编译我的应用程序。 (已经使用 netbeans_ 配置了 GCC 和 G++。下面是我使用 netbeans 构建代码时遇到的错误:

    cd 'D:\University\PARALLEL\ParallelTesting'
C:\dev_softwares\cygwin64\bin\make.exe -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/d/University/PARALLEL/ParallelTesting'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/paralleltesting.exe
make[2]: Entering directory '/cygdrive/d/University/PARALLEL/ParallelTesting'
mkdir -p dist/Debug/Cygwin-Windows
g++ -o dist/Debug/Cygwin-Windows/paralleltesting build/Debug/Cygwin-Windows/main.o
build/Debug/Cygwin-Windows/main.o: In function `main':
/cygdrive/d/University/PARALLEL/ParallelTesting/main.cpp:26: undefined reference to `omp_get_thread_num'
/cygdrive/d/University/PARALLEL/ParallelTesting/main.cpp:26:(.text+0x15): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `omp_get_thread_num'
/cygdrive/d/University/PARALLEL/ParallelTesting/main.cpp:32: undefined reference to `omp_get_num_threads'
/cygdrive/d/University/PARALLEL/ParallelTesting/main.cpp:32:(.text+0x34): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `omp_get_num_threads'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/Cygwin-Windows/paralleltesting.exe' failed

p.s:并行编程世界的新手,并且已经使用 netbeans 配置了 gcc。

My gcc configuration FYI

Versions

我的测试并行代码:

#include <omp.h>
#include <stdio.h>
#include <stdlib.h>

int main (int argc, char *argv[])
{
int nthreads, tid;

/* Fork a team of threads giving them their own copies of variables */
#pragma omp parallel private(nthreads, tid)
{

/* Obtain thread number */
tid = omp_get_thread_num();
printf("Hello World from thread = %d\n", tid);

/* Only master thread does this */
if (tid == 0)
{
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}

} /* All threads join master thread and disband */

}

最佳答案

下面是我所做的并且有效。感谢@Hristolliev。

If it is a managed C/C++ project, then compiler options can be specified in project properties -> Build -> C++ Compiler -> Additional Options.

enter image description here

关于c++ - 在配置了 g++ 和 gcc 的 netbeans 中使用 -fopenmp 编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41354144/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com