Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cmake fortran在linux上对MAIN__;的未定义引用_Linux_Cmake_Fortran_Gfortran - Fatal编程技术网

cmake fortran在linux上对MAIN__;的未定义引用

cmake fortran在linux上对MAIN__;的未定义引用,linux,cmake,fortran,gfortran,Linux,Cmake,Fortran,Gfortran,我试图让一个cmake构建系统在linux上运行。该项目包含一组可执行文件和两个库。其中一个可执行文件首先构建为库,然后该库与包含man子例程的对象文件链接。之所以这样做是因为其余的可执行文件依赖于该库。棘手的是,主子程序是在其他源代码所依赖的模块内定义的,因此需要在其他源代码之前编译。其效果是将主子例程添加到结果库中。这在MacOSX上似乎很好,但在Linux上链接状态失败 故障部件的cmake文件如下所示 cmake_minimum_required (VERSION 2.8) # Cre

我试图让一个cmake构建系统在linux上运行。该项目包含一组可执行文件和两个库。其中一个可执行文件首先构建为库,然后该库与包含man子例程的对象文件链接。之所以这样做是因为其余的可执行文件依赖于该库。棘手的是,主子程序是在其他源代码所依赖的模块内定义的,因此需要在其他源代码之前编译。其效果是将主子例程添加到结果库中。这在MacOSX上似乎很好,但在Linux上链接状态失败

故障部件的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时,它失败了

Linux上的
make VERBOSE=1
的输出产生

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
在MacOSX上,我得到

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上会失败。

结果我列出了错误的文件,其中包含main方法。gfortran的更高版本似乎可以从库中的链接“MAIN_uuuuuu”,而gfortran-4.4则不能