Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Compilation 使用gfortran链接库语法 C++中,如果我想做自定义编译(意思是链接附加库),我通常会做以下操作: g++ filename -o outputname -I/include_libraries_here -L/link_libraries_here -rpath=path_for_dynamic_linking_here_Compilation_Fortran_G++_Gfortran_Dynamic Linking - Fatal编程技术网

Compilation 使用gfortran链接库语法 C++中,如果我想做自定义编译(意思是链接附加库),我通常会做以下操作: g++ filename -o outputname -I/include_libraries_here -L/link_libraries_here -rpath=path_for_dynamic_linking_here

Compilation 使用gfortran链接库语法 C++中,如果我想做自定义编译(意思是链接附加库),我通常会做以下操作: g++ filename -o outputname -I/include_libraries_here -L/link_libraries_here -rpath=path_for_dynamic_linking_here,compilation,fortran,g++,gfortran,dynamic-linking,Compilation,Fortran,G++,Gfortran,Dynamic Linking,我将如何使用gfortran做类似的事情。我试过: gfortran filename -o outputname -I/include_libraries_here -L/link_libraries_here -rpath=path_for_dynamic_linking_here 到目前为止,语法-I和-L仍然有效,这表明我成功地链接并包含了这些库。但是,gfortran似乎不将rpath识别为有效命令 请让我知道,谢谢你 链接期间不必使用rpath。当然可以 请看这里: #inclu

我将如何使用gfortran做类似的事情。我试过:

gfortran filename -o outputname -I/include_libraries_here -L/link_libraries_here -rpath=path_for_dynamic_linking_here 
到目前为止,语法-I和-L仍然有效,这表明我成功地链接并包含了这些库。但是,gfortran似乎不将rpath识别为有效命令


请让我知道,谢谢你

链接期间不必使用rpath。当然可以

请看这里:

#include <stdio.h>

void fun() {
  printf("Hello from C\n");
}
然后,我们可以编译以下代码:

program hello
  print *, "Hello World!"
  call fun()
end program hello
像这样:

gcc -fPIC -shared -o libfun.so fun.c
# without -rpath
gfortran -fno-underscoring -o hello -L. -lfun hello.f90
# in this case you have to make sure libfun.so is in LD_LIBRARY_PATH

# with rpath
gfortran -fno-underscoring -o hello -L. -Wl,-rpath=`pwd` -lfun hello.f90
# in this case, library will be properly located at runtime
这将允许从共享库调用函数

./hello
 Hello World!
Hello from C
-rpath是ld的参数

-rpath=dir
           Add a directory to the runtime library search path.  This is used when linking an ELF executable with shared objects.  All -rpath arguments are concatenated
           and passed to the runtime linker, which uses them to locate shared objects at runtime.
有用链接:


为什么看起来如此?发生了什么?编译器说rpath不是有效的命令。我还试着使用just-R,仍然是相同的错误。那么-Wl,rpath。。。。不记得细节了,我没用过。