为什么不在使用FORTRAN功能的C上链接这样的项目

时间:2016-05-10 14:11:20

标签: c++ c cmake fortran clion

有一个cpp源,它们使用fortran函数。我也为我的项目使用cmake,但我无法链接它。我做错了什么?

main.cpp文件:

#include <stdio.h>
extern "C" {
void showm(void);
}
int main (void) {
showm();
return 0;
}

fort.f90文件:

subroutine showm
print *, "fort "
end subroutine showm

我在项目中使用cmake:

cmake_minimum_required(VERSION 3.4)
project(main)
enable_language(CXX)
enable_language (Fortran)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
set(FORTRAN_SOURCES fort.f90)
add_library(F_OBJECTS_LIB ${FORTRAN_SOURCES})
add_executable(main ${SOURCE_FILES})
target_link_libraries(main F_OBJECTS_LIB)

所以错误的文字是:

/home/mk/clion-2016.1.1/bin/cmake/bin/cmake --build /home/mk/.CLion2016.1/system/cmake/generated/proba- c5f6dd60/c5f6dd60/Debug --target all -- -j 2
[ 50%] Built target F_OBJECTS_LIB
Scanning dependencies of target main
[ 75%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[100%] Linking CXX executable main
CMakeFiles/main.dir/main.cpp.o: In function `main':
/home/mk/Рабочий стол/proba/main.cpp:4: undefined reference to `showm()'
collect2: error code 1

0 个答案:

没有答案