- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>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?
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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"
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
> 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.
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.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page