[英]calling fortran subroutines from c++
我想從C ++調用Fortran子例程。 由於我的程序需要包括Deal.ii中的某些庫(微分方程分析庫),因此我使用CMake創建了makefile。 我的問題如下:
在此先多謝! 勒布
PS .:這是當前的CMakeLists.txt:
##
# CMake script for the SIMP program:
##
# Set the name of the project and target:
SET(TARGET "SIMP")
# Declare all source files the target consists of:
SET(TARGET_SRC
${TARGET}.cc
# You can specify additional files here!
)
# Usually, you will not need to modify anything beyond this point...
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
FIND_PACKAGE(deal.II 8.0 QUIET
HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
)
IF(NOT ${deal.II_FOUND})
MESSAGE(FATAL_ERROR "\n"
"*** Could not locate deal.II. ***\n\n"
"You may want to either pass a flag -DDEAL_II_DIR=/path/to/deal.II to cmake\n"
"or set an environment variable \"DEAL_II_DIR\" that contains this path."
)
ENDIF()
DEAL_II_INITIALIZE_CACHED_VARIABLES()
PROJECT(${TARGET})
DEAL_II_INVOKE_AUTOPILOT()
看看http://www.cmake.org/Wiki/CMakeForFortranExample
如果您使用的是gfortran,那么您唯一需要的就是
enable_language(Fortran)
get_filename_component部分檢查您是否存在編譯器。 知道選擇哪個是非常有用的,特別是如果已安裝gfortran,g95和ifort。
現在,我使用以下CMakeLists.txt文件,它可以正常工作。
##
# CMake script for the SIMP program:
##
# Set the name of the project and target:
set (TARGET "SIMP")
set (CMAKE_Fortran_COMPILER "gfortran")
set (CMAKE_Fortran_FLAGS_RELEASE "-O2 -m32")
set (CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -m32")
set (CMAKE_CXX_FLAGS_DEBUG "-O0 -g -m32")
# Declare all source files the target consists of:
SET(TARGET_SRC
${TARGET}.cc
# You can specify additional files here!
fortran_subroutine.f
)
# Usually, you will not need to modify anything beyond this point...
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
FIND_PACKAGE(deal.II 8.0 QUIET
HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
)
IF(NOT ${deal.II_FOUND})
MESSAGE(FATAL_ERROR "\n"
"*** Could not locate deal.II. ***\n\n"
"You may want to either pass a flag -DDEAL_II_DIR=/path/to/deal.II to cmake\n"
"or set an environment variable \"DEAL_II_DIR\" that contains this path."
)
ENDIF()
DEAL_II_INITIALIZE_CACHED_VARIABLES()
PROJECT(${TARGET} C CXX Fortran)
DEAL_II_INVOKE_AUTOPILOT()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.