2012-07-17 52 views
0

我试图获得一个在linux上工作的cmake构建系统。该项目包含一堆可执行文件和两个库。其中一个可执行文件首先被构建为一个库,然后该库与包含man子例程的目标文件相链接。这是因为其他可执行文件依赖于该库。棘手的部分是主子程序是在模块内部定义的,其余的源依赖于它,所以这需要在其余源之前编译。结果是主子例程被添加到结果库中。这似乎在Mac OS X上正常工作,但Linux上的链接状态失败。cmake fortran在linux上对MAIN__的未定义引用

发生故障的部分CMake的文件看起来像

cmake_minimum_required (VERSION 2.8) 

# Create an empty variable to hold all the source files. 
set (vmec_sources "") 

# Add subdirectory for all the sources. 
add_subdirectory (Sources) 

add_library (vmec STATIC ${vmec_sources}) 
add_dependencies (vmec stell) 

# Define an executable and link all libraries. 
add_executable (xvmec ${CMAKE_CURRENT_SOURCE_DIR}/Sources/General/vmec_main.f) 
add_dependencies (xvmec vmec) 
target_link_libraries (xvmec vmec stell) 

if ((NOT ${NETCDF_C} STREQUAL "") AND (NOT ${NETCDF_F} STREQUAL "")) 
    target_link_libraries (xvmec ${NETCDF_C} ${NETCDF_F}) 
endif() 

当运行cmake的,一切配置罚款和产生,当我运行make Mac OS X中的一切工作正常make文件。当我在Linux上运行make时失败。

make VERBOSE=1 Linux上的输出产生

Linking Fortran executable ../build/bin/xvmec 
cd /home/user/reconstruction/VMEC2000 && /usr/bin/cmake -E cmake_link_script CMakeFiles/xvmec.dir/link.txt --verbose=1 
/usr/bin/gfortran  -cpp -D NETCDF -I /usr/include CMakeFiles/xvmec.dir/Sources/General/vmec_main.f.o -o ../build/bin/xvmec -rdynamic ../build/lib/libvmec.a ../build/lib/libstell.a /usr/lib/libnetcdf.so /usr/lib/libnetcdff.so 
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/libgfortranbegin.a(fmain.o): In function `main': 
(.text+0x26): undefined reference to `MAIN__' 
collect2: ld returned 1 exit status 
make[2]: *** [build/bin/xvmec] Error 1 
make[2]: Leaving directory `/home/user/reconstruction' 
make[1]: *** [VMEC2000/CMakeFiles/xvmec.dir/all] Error 2 
make[1]: Leaving directory `/home/user/reconstruction' 
make: *** [all] Error 2 

在Mac OS X,我得到

Linking Fortran executable ../build/bin/xvmec 
cd /Users/user/repo/trunk/VMEC2000 && "/Applications/CMake 2.8-8.app/Contents/bin/cmake" -E cmake_link_script CMakeFiles/xvmec.dir/link.txt --verbose=1 
/usr/local/bin/gfortran  -framework Accelerate -cpp -D DARWIN -D NETCDF -I /Users/user/NetCDF/include -O3 -ftree-vectorize -m64 -march=native -fomit-frame-pointer -falign-functions -mfpmath=sse CMakeFiles/xvmec.dir/Sources/General/vmec_main.f.o -o ../build/bin/xvmec ../build/lib/libvmec.a ../build/lib/libstell.a /Users/user/NetCDF/lib/libnetcdf.dylib /Users/user/NetCDF/lib/libnetcdff.dylib 
"/Applications/CMake 2.8-8.app/Contents/bin/cmake" -E cmake_progress_report /Users/user/repo/trunk/CMakeFiles 100 
[100%] Built target xvmec 

链接线看起来是连接所有同样的东西在正确的顺序,以便我不明白为什么这在Linux上失败。

回答

0

原来,我列出了包含主要方法的错误文件。看起来,gfortran的后期版本可以从库内部链接'MAIN__',而gfortran-4.4则不能。

相关问题