[CMake] Fortran project problem (static linking)

Michael Wild themiwi at gmail.com
Tue Nov 17 07:35:50 EST 2009


On 17. Nov, 2009, at 4:31 , DONG Li wrote:

> Hi all,
>
> I am trying to use CMake as my Fortran project build tool, it is a  
> wonderful project guard!. But a annoying problem comes up. I  
> searched all around the internet, but no easy document for me : (.  
> Since I want to use static-linking, the Intel Fortran compiler  
> complains "undefined reference to" when it links objects for an  
> executable.
>
> The structure of the project is:
>
> CMakeLists.txt  core  init_data  main  test  util
>
> and there will be static libraries under util and core as libutil.a  
> and libcore.a. Further more, libcore.a depends on libutil.a.
>
> Finally, an executable will be generated under main which uses  
> libcore.a and libutil.a.
>
> So how can I accomplish this? Thanks very much. I really want to  
> learn CMake~
>
> Best regards,
>
> DONG Li_______________________________________________
>

CMakeLists.txt
---------------
cmake_minimum_required(VERSION 2.6)
project(SuperDuper Fortran)
add_subdirectory(util)
add_subdirectory(core)
add_subdirectory(main)

util/CMakeLists.txt
-------------------
add_library(util util1.f util2.f)

core/CMakeLists.txt
-------------------
add_library(core core1.f core2.f)
target_link_libraries(core util)

main/CMakeLists.txt
-------------------
add_executable(${PROJECT_NAME} main1.f main2.f)
target_link_libraries(${PROJECT_NAME} util core)


HTH

Michael


More information about the CMake mailing list