Fortran Coder

查看: 1513|回复: 0
打印 上一主题 下一主题

[求助] vscode中用cmakelists链接hdf5

[复制链接]

9

帖子

3

主题

0

精华

入门

F 币
36 元
贡献
14 点
跳转到指定楼层
楼主
发表于 2023-7-25 10:40:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请问一下,在vscode中通过cmakelists链接hdf5时,会出现[build] f951.exe: Fatal Error: Reading module 'hdf5' at line 1 column 2: Unexpected EOF,这个错误怎么解决呢



cmake_minimum_required(VERSION 3.23)

project(P_HyLand Fortran)
enable_language(Fortran)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})


# save the library
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
# Fortran .mod
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_SOURCE_DIR}/include)

find_package(OpenMP REQUIRED)


SET(HDF5_USE_STATIC_LIBRARIES ON)

SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "D:/AppGallery/software/HDF_Group/HDF5/1.12.1/")

find_package(HDF5 MODULE REQUIRED COMPONENTS Fortran HL)


message("fortran compiler is ${CMAKE_fortran_COMPILER}")
# write the HDF5 finding result
message("HDF5_FOUND is : ${HDF5_FOUND}")
message("HDF5_INCLUDE_DIRS is : ${HDF5_INCLUDE_DIRS}")
message("HDF5_VERSION is : ${HDF5_VERSION}")
message("HDF5_LIBRARIES is ${HDF5_LIBRARIES}")
message("HDF5_HL_LIBRARIES is ${HDF5_HL_LIBRARIES}")


# detect the operating system
IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
    MESSAGE(STATUS "current platform: Linux ")
    file(READ Control.Project FILE_CONTENTS)
    string(REPLACE "\\" "/" FILE_CONTENTS "${FILE_CONTENTS}")
    file(WRITE Control.Project "${FILE_CONTENTS}")

ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
    MESSAGE(STATUS "current platform: Windows")
    file(READ Control.Project FILE_CONTENTS)
    string(REPLACE "/" "\\" FILE_CONTENTS "${FILE_CONTENTS}")
    file(WRITE Control.Project "${FILE_CONTENTS}")

ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
    MESSAGE(STATUS "current platform: Mac OS X")
    file(READ Control.Project FILE_CONTENTS)
    string(REPLACE "\\" "/" FILE_CONTENTS "${FILE_CONTENTS}")
    file(WRITE Control.Project "${FILE_CONTENTS}")

ELSE ()
    MESSAGE(STATUS "other platform: ${CMAKE_SYSTEM_NAME}")
ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux")

if (OPENMP_FOUND)
    message("openMP found")
    set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
endif()


include_directories("${HDF5_INCLUDE_DIRS}")

file(GLOB_RECURSE SRCS RELATIVE ${PROJECT_SOURCE_DIR} src/*)

add_executable(PHyL_v1 ${SRCS})

# target_link_libraries(PHyL_v1 ${HDF5_LIBRARIES})
target_link_libraries(PHyL_v1 HDF5::HDF5)


以上是我在cmakelists中的设置,希望大家可以提供帮助


分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-11-23 14:51

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表