指定的OpenMP到GCC [英] Specify OpenMP to GCC
问题描述
有关的OpenMP,当我的code为使用的功能的API中(例如,omp_get_thread_num()),而无需使用其指令(例如那些的#pragma OMP ...),
For OpenMP, when my code is using the functions in its API (for example, omp_get_thread_num()) without using its directives (such as those #pragma omp ...),
-
为什么直接指定libgomp.a到
海湾合作委员会,而不是使用-fopenmp
不工作,如
why directly specifying libgomp.a to gcc instead of using -fopenmp doesn't work, such as
gcc hello.c /usr/lib/gcc/i686-linux-gnu/4.4/libgomp.a -o hello
更新:我刚刚发现链接到libgomp.a不起作用,而是链接到libgomp.so作品。这是否意味着OpenMP的不能是静态链接?
Update: I just found that linking to libgomp.a does not work, but linking to libgomp.so works. Does it mean OpenMP can not be static linked?
为什么-fopenmp只能无
指定库文件
Why -fopenmp only works without specifying the library files
gcc hello.c -fopenmp -o hello
更新:换句话说,使用-fopenmp时候,为什么不要求明确链接到libgomp.so
Update: In other words, when using -fopenmp, why explicit linking to libgomp.so is not required?
为什么这也是编译:
gcc hello.c -L/usr/lib/gcc/i686-linux-gnu/4.4/ -lgomp -o hello
这将忽略OpenMP指令
在code,如果有任何?
Will this ignore OpenMP directives in the code if there is any?
感谢和问候!
推荐答案
在一般情况下,请记住,指令和功能是不同的东西;前者是由 -fopenmp
控制,后者被控制通过链接到OpenMP库。
In general, keep in mind that the directives and the functions are different things; the former are controlled by -fopenmp
and the latter are controlled by linking to the OpenMP library.
-
(更新,其中包含注释)尝试使用
-fopenmp
和-static
选项静态链接的OpenMP。因为这意味着-lgomp -lrt
,以下命令将无法正确编译,除非您还指定librt.a $ C $的位置C>。
(Updated to incorporate comments) Try using the
-fopenmp
and-static
options to statically link OpenMP. Because this implies-lgomp -lrt
, the following command won't compile correctly unless you also specify the location oflibrt.a
.
gcc hello.c /usr/lib/gcc/i686-linux-gnu/4.4/libgomp.a -o hello
(更新,其中包含注释)我想,下面的命令是否正确编译,因为OpenMP库已经在你的库路径和你系统的动态连接器会自动链接 libgomp.so
。
(Updated to incorporate comments) I imagine that the following command is compiling correctly because the OpenMP library is already in your library path and your system's dynamic linker is automatically linking with libgomp.so
.
gcc hello.c -fopenmp -o hello
下面的命令可能是正确编译,因为它是连接到共享对象的OpenMP( libgomp.so
)。请注意, -static
选项的不的使用。
The following command is probably compiling properly because it is linking to the shared object for OpenMP (libgomp.so
). Note that the -static
option is not used.
gcc hello.c -L/usr/lib/gcc/i686-linux-gnu/4.4/ -lgomp -o hello
如果您不指定 -fopenmp
选项,OpenMP指令应该被忽略。
If you don't specify the -fopenmp
option, OpenMP directives should be ignored.
这篇关于指定的OpenMP到GCC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!