-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
142 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
cmake_minimum_required(VERSION 3.14...3.23) | ||
cmake_minimum_required(VERSION 3.19...3.23) | ||
project(abi_check LANGUAGES C Fortran) | ||
|
||
enable_testing() | ||
|
||
add_library(addone OBJECT addone.c) | ||
add_executable(main_f main.f90 $<TARGET_OBJECTS:addone>) | ||
if(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel") | ||
set_target_properties(main_f PROPERTIES LINKER_LANGUAGE Fortran) | ||
else() | ||
set_target_properties(main_f PROPERTIES LINKER_LANGUAGE C) | ||
endif() | ||
add_test(NAME Fortran_main COMMAND main_f) | ||
|
||
add_library(addone_f OBJECT addone.f90) | ||
|
||
add_executable(main_c main.c $<TARGET_OBJECTS:addone_f>) | ||
set_target_properties(main_c PROPERTIES LINKER_LANGUAGE C) | ||
add_test(NAME C_main COMMAND main_c) | ||
|
||
add_executable(main main.f90 $<TARGET_OBJECTS:addone>) | ||
set_tests_properties(Fortran_main C_main PROPERTIES TIMEOUT 10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
extern int addone(int); | ||
|
||
int addone(int N){ | ||
return N + 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module adder | ||
|
||
use, intrinsic :: iso_c_binding, only : C_INT | ||
implicit none (type, external) | ||
|
||
contains | ||
|
||
pure integer(C_INT) function addone(N) bind(C) | ||
integer(C_INT), intent(in), value :: N | ||
addone = N + 1 | ||
end function addone | ||
|
||
end module adder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <stdio.h> | ||
|
||
extern int addone(int); | ||
|
||
|
||
int main(void) { | ||
|
||
if(addone(2) != 3) { | ||
fprintf(stderr, "2 + 1 != %d", addone(2)); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
program adder | ||
|
||
implicit none | ||
use, intrinsic :: iso_fortran_env, only : stderr=>error_unit | ||
|
||
implicit none (type, external) | ||
|
||
interface | ||
|
||
integer function addone(N) bind(C) | ||
integer, intent(in), value :: N | ||
end function addone | ||
|
||
end interface | ||
|
||
|
||
if (addone(2) /= 3) error stop "unexpected addone result" | ||
if (addone(2) /= 3) then | ||
write(stderr,*) "ERROR: 2+1 /= ", addone(2) | ||
error stop | ||
endif | ||
|
||
print *, "OK: 2+1=3" | ||
print *, "OK: Fortran main with C libraries" | ||
|
||
|
||
end program |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.