2016-12-28 56 views
1

我正在嘗試配置我的NetBeans以在我的並行編程C++代碼上工作。我可以使用命令行(cygwin)編譯該代碼,但現在爲了進一步調試和編碼更復雜的事情,我想轉移到某個IDE和選定的整潔人員來完成我的任務。有人可以建議我如何添加-fopenmp編譯我的應用程序,一旦我點擊在netbeans中構建我的應用程序按鈕。 (已經配置了GCC和G ++與netbeans_下面是如果我建我使用的代碼的NetBeans我得到的錯誤:在配置爲g ++和gcc的netbeans中編譯-fopenmp

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 

PS:新並行編程的世界,並與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 */ 

} 
+0

是的,我做到了。更新了我的問題,添加了我的測試並行程序。 – ManinGreen

+1

有一個地方可以添加額外的編譯器標誌:[see here](http://forums.netbeans.org/post-51329.html) –

+0

很酷,謝謝它的工作。 – ManinGreen

回答

1

以下是我所做的工作。感謝@Hristolliev。

如果它是一個託管C/C++的項目,然後編譯選項可以在項目屬性中指定 - >構建 - > C++編譯器 - > 附加選項。

enter image description here