Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

64 bit Compiler - C/fortran code

baldas10
Beginner
994 Views
Hi, I have some code that I would like to compile in 32 and 64-bits.
Flipping pure Fortran code from 32 to 64 bits works and runs fine.
But the issues is when mixing C/C++/Fortran code.
In particular, I have the problem in the subroutine ConvertFtoCstring: the compiler not find the definition.

What is the problem?

Thanks in advance
0 Kudos
5 Replies
mecej4
Honored Contributor III
994 Views
>In particular, I have the problem in the subroutine ConvertFtoCstring: the compiler not find the definition. What is the problem?

You have stated that there is a problem. The nature of the problem, however, is still undefined.

Is ConvertFtoCstring a user defined subprogram? How is it defined and used? What is its interface?

What is the exact error message from the compiler or linker?
0 Kudos
baldas10
Beginner
994 Views
ConvertFtoCstring is a C subprogram (no user defined).
In my code I dont'have a interface, but use the subroutine (no problem in 32 bit version).

The error message from the linker is "error LNK2019 unresolved external symbol"
0 Kudos
mecej4
Honored Contributor III
994 Views
The error message from the linker is "error LNK2019 unresolved external symbol"

That is incomplete -- what was the symbol name that was flagged as "unresolved"?

In order to call the C function ConvertFtoCstring, you need to have the symbol in a 64-bit .obj or .lib file in order to link it successfully with 64-bit Fortran objects.
0 Kudos
John4
Valued Contributor I
994 Views
Or you could write your own version of ConvertFtoCstring. Something like:

[fortran]    pure subroutine f2cstring(f, c)
        use ISO_C_BINDING
        character(*), intent(IN) :: f
        character(KIND = C_CHAR), intent(OUT) :: c(:)
        integer :: i
        do i = 1, LEN_TRIM(f)
            c(i) = f(i:i)
        enddo
        c(LEN_TRIM(f) + 1:) = C_NULL_CHAR
    end subroutine
[/fortran]

This has the advantage of not depending on whether the word size is 32- or 64-bits.

But if you insist on using ConvertFtoCstring, according to Google, the code is:

[cpp]int _stdcall convertFtoCstring(char *CString,int FString)
{
    return (int)(char *)strcpy(CString,(const char *)FString);
}
[/cpp]

Notice the calling convention and the (not-so-safe) usage of strcpy.

0 Kudos
mecej4
Honored Contributor III
994 Views
> int_stdcallconvertFtoCstring

Note that OP stated that things worked fine in 32-bit, and _stdcall is not applicable to 64-bit. However, if your source code does what he wants the function to do, his problem is solved.
0 Kudos
Reply