[CMake] Fortran project problem (static linking)

Michael Wild themiwi at gmail.com
Wed Nov 18 00:55:07 EST 2009


On 18. Nov, 2009, at 6:18 , 董理 wrote:

> Michael Wild 写道:
>>
>> 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
> Hi Michael,
>
> I have tried this pattern, but it doesn't work. Forgot to say that  
> my programs are in Fortran 90 with several modules. Does this matter?
>
>
> Best regards,
>
> DONG Li


Well, "doesn't work" certainly isn't enough information. Which version  
of CMake are you using? What are the errors you get? Still the linking  
errors? Then you must be missing either some sources, some external  
libraries or have typos in your code.

And, please, keep the messages on the list by using the "reply-all"  
button.

Michael


More information about the CMake mailing list