- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am trying to call c from fortran following this: Chapter 11 C-Fortran Interface (Fortran Programming Guide) (oracle.com)
Simple Data Types
but can't find c function when link. The C function is csim_, but the linker wants _csim. What I have done wrong?
fmain.f
integer i
real r
external CSim
i = 100
call CSim(i,r)
end
csim.c
void csim_(int *i, float *r)
{
*r = *i;
}
error:
D:\intel\FcallC>icx /c csim.c
Intel(R) oneAPI DPC++/C++ Compiler for applications running on IA-32, Version 2021.2.0 Build 20210317
Copyright (C) 1985-2021 Intel Corporation. All rights reserved.
D:\intel\FcallC>ifort fmain.f csim.obj /link /out:a.exe
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on IA-32, Version 2021.2.0 Build 20210228_000000
Copyright (C) 1985-2021 Intel Corporation. All rights reserved.
Microsoft (R) Incremental Linker Version 14.16.27040.0
Copyright (C) Microsoft Corporation. All rights reserved.
-out:fmain.exe
-subsystem:console
/out:a.exe
fmain.obj
csim.obj
fmain.obj : error LNK2019: unresolved external symbol _CSIM referenced in function _MAIN__
a.exe : fatal error LNK1120: 1 unresolved externals
Cheers,
Cean
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The documentation contains an entire chapter on mixed language programming. Fortran 2003+ provides a portable (i.e., compiler independent) facility for using C and Fortran together.
You used the GNU convention of naming the C external symbol in lower-case, with an underscore appended: "csim_". For Intel Fortran, use "CSIM", instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was wondering why it is looking for all capital letters. After also removing the underscore, I got an exe file.
Thank you very much.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page