- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Maybe C++ is mangling the function name, I usually include an "extern "C" " to eliminate mangling in the C++ code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Either I don't understand your suggestion, or it's not the correct solution.
I inserted the extern "C" in front of the C++ declaration and I get the same error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jugoslav
This is the line that from the dumpbin resultant file (temp.txt) which has the InitComPort definition in it.
1DD 00000048 SECT56 notype () External | ?InitComPort@@$$J14YGEPAX@Z (unsigned char __stdcall InitComPort(void *))
I confess I don't know a think about the .NET environment or programming in the Microsoft world. I'm and old VMS FORTRAN and MACRO programmer with some UNIX C/C++ experience. I'm assuming at this point that the InitComPort call needs to be referenced not as a C alias but as an _stdcall alias, but when I do that I don't get anything different. This baffles me.
So, then Iproceeded as follows:
1)Changed the project properties: I changed the properties in the C++ project, under C/C++ / Advanced / Calling Convention, to _cdecl (/Gd) and in the Fortran project, under Fortran / External Procedures / Calling Convention, to C, REFERENCE. This returned the following error:
error LNK2001: unresolved external symbol __CorExeMain@0
Ran thedumpbin command and found the following resultant InitComPort definition:
1DD 00000048 SECT56 notype () External | ?InitComPort@@$$J0YAEPAX@Z (unsigned char __cdecl InitComPort(void *))
2) Changed the project properties, again: I changed the properties in the C++ project, under Calling Convention, to__stdcall (/Gz)and in the Fortran project, under Calling Convention, to STDCALL, REFERENCE. This returned the following errors:
error LNK2019: unresolved external symbol _InitComPort referenced in function _main__
error LNK2019: unresolved external symbol _MAIN__ referenced in function _main
Ran thedumpbin command and found the following resultant InitComPort definition:
1DD 00000048 SECT56 notype () External | ?InitComPort@@$$J14YGEPAX@Z (unsigned char __stdcall InitComPort(void *))
error LNK2019: unresolved external symbol _InitComPort referenced in function _main__
error LNK2019: unresolved external symbol _MAIN__ referenced in function _main
Ran thedumpbin command and found the following resultant InitComPort definition:
1DD 00000048 SECT56 notype () External | ?InitComPort@@$$J14YGEPAX@Z (unsigned char __stdcall InitComPort(void *))
4) Not yet tired of being rejected, I tried another change tothe project properties: Ileft the properties in the C++ project, under Calling Convention,as__stdcall (/Gz)and in the Fortran project, under Calling Convention, to defauolt. This returned the following error:
error LNK2019: unresolved external symbol _InitComPort referenced in function _MAIN__
Ran thedumpbin command and found the following resu ltant InitComPort definition:
1DD 00000048 SECT56 notype () External | ?InitComPort@@$$J14YGEPAX@Z (unsigned char __stdcall InitComPort(void *))
I am completely baffled....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No matter what you didwith calling conventions, you don't appear to have specified extern "C" correctly -- the InitComPort always has C++ name mangling (InitComPort@@$$J0YAEPAX@Z or like,variations coming from __stdcall vs. __cdecl).
Your initial setup was fine. Fortran compiler setting don't really affect anything if you have explicit INTERFACE with ALIAS and calling convention specified.
Just in case, specify extern "C" in both declaration(.h file if any) and definition(.cpp file) of InitComPort. (I'm not sure how exactly it works, but having it in both places is a safe bet).
(C vs C++) Name mangling and calling convention are not quite related; due to possibilities of function overloading and other language features, C++ has toencode all information about routine type, calling convention, and argument types in decorated name. This encoding is compiler-specific. You can specify any of (cdecl, stdcall, fastcall) calling convention in C++, but you have to match it in Fortran INTERFACE (fastcall not supported).
Quote from MSDN:
A decorated name for a C++ function contains the following information:
The function and class names are encoded in the decorated name. The rest of the decorated name is a code that has internal meaning only for the compiler and the linker. The following are examples of undecorated and decorated C++ names.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jugoslav
Thank you so much for all your information!
I have finally resolved this issue, but it was a little more that just the C++ mangling of the name, which I did not understand verywell until your last email. (Now it actually makes some sense!)
Apparently, my problem also had issue with programming in the .NET environment. Itagged onto a .NET programmer who just couldn't believe the code wasn't linking once I had placed the extern "C" command in the code. After playing around with several of the two projects' settings we finally corrected the linking problem.
Let me summarize in case someone else ever sees the same thing and the extern "C" doesn't correct the situation:
In the FORTRAN project properties (which is the calling project, in this case):
- The Fortran / External Procedures / Calling Convention should be C, REFERENCE (although, this can be handled in the code with an INTERFACE command).
- The Linker / General / Additional Library Directories MAY need to have the path for the library you're about to link to declared.
In the C++ project properties (which is a library of called routines, in this case):
- The C/C++ / Advanced / Calling Conventionshould be __stdcall (/Gz).
In the C++source fileproperties (the only place you can find this one)
- The C/C++ / General / Compile As Managed should be Not using managed extensions. (Compile As Managed controls the /clr parameter on the command line and you don't want the /clr) (This was the reason that Iwas getting the following error
error LNK2001: unresolved external symbol __CorExeMain@0)
This last item (/clr param) was the kicker. If I change it back to Compile As Managed or
Thanks again for all your help, it would have taken me much longer to resolve this without your support.
Bonnie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
(had to exchange STDCALL for C)
By the way, the stripped down code was running before the change, but the stack is very shallow in the stripped down version. The full blown program would have likely failed with the incompatibility.
Thanks, again.
Bonnie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
FWIW, personally I prefer to leave compiler defaults as much as possible, and to spell out any specifics (via !DEC$ATTRIBUTES or __stdcall).
There's no much real difference in performance of cdecl vs. stdcall. Cdecl is more widely accepted and it's universal on UNIXes, but stdcall has its merits as well, but the differences are slight. It's tougher to obtain fandango on stack with cdecl than with stdcall, but then, it means just that programmer's errors are hidden. Ideally, it shouldn't matter which one you use, as long as you pay attention to interactions (between different compilers).
Jugoslav

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