4

我正在尝试使用一个外部模块为我的 Fortran 项目编写一个 cmake 列表,并且两者都必须与一个没有任何 cmake find (findlib) 包的外部库链接。到目前为止,我的 CMakeLists.txt 看起来像这样:

cmake_minimum_required (VERSION 2.6)

project (Project 1)

enable_language (C Fortran)

set(extern_INCLUDE /home/path/lib/libdir/include/)
set(extern_LIB /home/path/lib/libdir/lib)
include_directories(${extern_INCLUDE})
link_directories (${extern_LIB})

add_library(mymodule STATIC mymodule.f90)
set(main-source_SRC main-source.f)
add_executable(main-source ${main-source_SRC})
#the name of the external library located in /home/path/lib/libdir/lib is    libexternlib.so
target_link_libraries(main-source mymodule externlib) 

创建了一个 libmymodule.a 并且绝对没有必要(或者就此而言共享一个)。我不想生成它们。如何避免它的生成并仍然编译 mymodule,生成 .o 和 .mod 以便能够与主程序和外部库链接?等效于 ifort -c 到 mymodule 和 ifort 到所有 .o。

4

2 回答 2

0

你有源代码mymodule。您可以包含mymodule.f90main-source_SRC. 这应该足够了。我希望以下工作,但我无法测试它。

cmake_minimum_required (VERSION 2.6)

project (Project 1)

enable_language (C Fortran)

set(extern_INCLUDE /home/path/lib/libdir/include/)
set(extern_LIB /home/path/lib/libdir/lib)
include_directories(${extern_INCLUDE})
link_directories (${extern_LIB})

set(main-source_SRC main-source.f mymodule.f90)
add_executable(main-source ${main-source_SRC})
#the name of the external library located in /home/path/lib/libdir/lib is    libexternlib.so
target_link_libraries(main-source externlib) 
于 2013-02-14T21:07:16.143 回答
0

The file libmymodule.a is a static library, and is created because the STATIC option in the add_library() function tells CMake to do so. Instead of STATIC, try using SHARED to create the shared library libmymodule.so - though I'm not sure it's the static bit you're worried about here.

If the external library does not come with a FindLib file, it may be easy enough to create one yourself. There are a number of examples in the FindLibs/ directory of the CMakeFiles package, which provides example CMake files, in particular for Fortran projects: http://cmakefiles.sf.net/

于 2013-03-02T16:24:04.810 回答