- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I made a c lib(csim.lib), then Fortran main (fmain.f) calls it through another c function (c_fortran_csim.c). I got this error:
MSVCRTD.lib(exe_main.obj) : error LNK2019: unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
It seems the Fortran and the C are not set in the same way. What setting should I change?
Cheers,
Cean
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to examine and fix your Visual Studio project settings. I do not use Visual Studio for building, and it is rather trivial to build your small example at the command line.
T:\lang\FcallC>icl /Od /c csim.c c_fortran_csim.c
T:\lang\FcallC>ifort /Od fmain.f csim.obj c_fortran_csim.obj
T:\lang\FcallC>fmain
100 100.0000
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want csim.lib instead of csim.obj.
I was using icx+ifort, now I changed to use icl+ifort, it seems working.
1. Create a c lib:
D:\FcallClib\clib>icl /c csim.c
Intel(R) C++ 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.
csim.c
D:\FcallClib\clib>LIB.EXE /OUT:csim.lib csim.obj
Microsoft (R) Library Manager Version 14.16.27040.0
Copyright (C) Microsoft Corporation. All rights reserved.
2. Create fortran application to call that c lib:
D:\FcallClib\FcallC>icl /c c_fortran_csim.c
Intel(R) C++ 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.
c_fortran_csim.c
D:\FcallClib\FcallC>ifort /DYNAMICBASE "D:/FcallClib/FcallC/csim.lib" fmain.f c_fortran_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
c_fortran_csim.obj
D:/FcallClib/FcallC/csim.lib
D:\FcallClib\FcallC>a
100 100.0000
Hope it will work with VS.
I want to use a third party lib and I can build it in VS, not in command line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@cean ,
Instead of the CMake approach, will you be willing to try instead what the vendor of the IDE you are trying (Microsoft with Visual Studio) documents as the approach for creating a static library project and how to reference it in a console app:
and then try to substitute that console app with a Fortran main program for which your other vendor (Intel) provides documentation along with its compiler reference:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think I need this Selecting a Version of the Intel® Fortran Compiler
But to select which c compiler to use.
My two projects, c project to create c lib and main project (fortran + c) to call that lib. MS-VS by default chose two no compatible ones. I need to change the c project to use icl compiler. There are no message shown in the Output Window which c compiler is used. How do I change?

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