0

使用http://openmp.org/wp/openmp-compilers/上的示例代码,我尝试在我的 Linux 机器(运行 OpenSUSE 12.2)上运行这个简单的程序,但未能让它编译。

这是示例代码。

#include <omp.h>
#include <stdio.h>
int main() {
#pragma omp parallel
printf("Hello from thread %d, nthreads %d\n",
        omp_get_thread_num(), omp_get_num_threads());
}

来自终端的片段。

Go Trojans >g++ -fopenmp try_openmp.cpp
/usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../x86_64-suse-linux/bin/ld:
   warning: librt.so.1, needed by /usr/lib64/gcc/x86_64-suse-linux/4.7/libgomp.so, not found (try using -rpath or -rpath-link)
/usr/lib64/gcc/x86_64-suse-linux/4.7/libgomp.so: undefined reference to `clock_getres@GLIBC_2.2.5'
/usr/lib64/gcc/x86_64-suse-linux/4.7/libgomp.so: undefined reference to `clock_gettime@GLIBC_2.2.5'
collect2: error: ld returned 1 exit status
Go Trojans >


Go Trojans >pwd
/usr/lib64
Go Trojans >ls -al | grep librt
-rw-r--r--   1 root root    381554 Dec 20 02:49 librt.a
lrwxrwxrwx   1 root root        15 Jan 23 05:23 librtm.so.4 -> librtm.so.4.8.0
-rwxr-xr-x   1 root root    126168 Jul 17  2012 librtm.so.4.8.0
-rw-r--r--   1 root root    393426 Dec 20 02:49 librt_p.a
lrwxrwxrwx   1 root root        17 Jan 23 05:12 librt.so -> /lib64/librt.so.1
Go Trojans >cd /lib64/
Go Trojans >pwd
/lib64
Go Trojans >ls -al | grep librt
-rwxr-xr-x  1 root root   42777 Jul 15  2012 librt-2.15.so
lrwxrwxrwx  1 root root      13 Aug 24 12:44 librt.so.1 -> librt-2.15.so
Go Trojans >

Go Trojans >g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/4.7/lto-wrapper
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.7 --enable-ssp --disable-libssp --disable-libitm --disable-plugin --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --enable-linker-build-id --program-suffix=-4.7 --enable-linux-futex --without-system-libunwind --with-arch-32=i586 --with-tune=generic --build=x86_64-suse-linux
Thread model: posix
gcc version 4.7.1 20120723 [gcc-4_7-branch revision 189773] (SUSE Linux)

G++/GCC 对我有用。如何让 OpenMP 为我工作?

有没有一种方法可以在不升级 GCC/g++ 的情况下更新 OpenMP?

4

0 回答 0