- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please help:
I've written some source code that I want to give to a colleague in the form of the compiled libraries (can't release code--that's a separate subject). I've written the code in C++ in MS Visual C++ environment. I want my colleague to be able to call some functions--I've made them "wrappers" in C++ so that they can manage the C++ class structures. My colleagues source code is written in Compaq Visual FORTRAN.
How does my colleague (a) include these libraries in his project, and (b) call my functions?
Here's my header file:
extern "C" void cInitializeObject( long* obj, char* namemodel , long* listfile);
and here' how I've told him to call it:
INTEGER*32obj
INTEGER*32 listfile
INTEGER*32 listfile
C I'm not sure how FORTRAN does strings ...
STRING*256 namemodel
STRING*256 namemodel
C I'm not sure how to make a string in FORTRAN:
namemodel = "mynamemodel"
CALL cInitializeObject(obj,namemodel,listfile)
Do we need to worry about FORTRAN naming conventions, parameter order, etc?
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I use C/C++ libraries with my Fortran code. It's not a big deal to link to them when you know the API format. Look for External Procedures (it may be slightly different since I don't have CVF anymore) under Fortran in the Project Properties menu selection. There are three main characteristics to check out: Calling Convention, Name Case, and String Arguments. The first probably should be "C, Reference." The second depends on the API. The selections are "Upper Case," "Lower Case," and "As Is." The one to choose is the case of the method name in the library. The only string selection I got to work was "After all arguments," but this is only necessary if you're passing strings/characters to C/C++ code.
To call the C/C++ method use "CALL method(a,b,c)" if void is used, otherwise use "x = method(a,b,c)."
To link to the library, you just include the library name (including path if it isn't searching in the proper directory) in the Input Parameters (I think it's called that) under the Link property.
Good luck.
To call the C/C++ method use "CALL method(a,b,c)" if void is used, otherwise use "x = method(a,b,c)."
To link to the library, you just include the library name (including path if it isn't searching in the proper directory) in the Input Parameters (I think it's called that) under the Link property.
Good luck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We've worked through some of these issues. We figured out the FORTRAN calling convention (we think), and we used __stdcall directive in the C code to get the names correct in the library.
We have two outstanding issues: in the FORTRAN code, we've declared a CHARACTER for a filename. FORTRAN is passing this as 8 bytes (pointer and string length?), but in the C code we're expecting a pointer (4 bytes), so we have a mismatch there.
We have a library conflict:
MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _fprintf already defined in libcd.lib(fprintf.obj)
(there are actually about 20 such conflicts for various stdlib calls)
I think this arises because we both use stdlib stuff in our code, and these functions have both been linked into our libraries. Suggested solutions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Whenever I see MSVCRTD complaining about conflicts I look to make sure all my libraries/executables are set to use all multithreaded or single-threaded run time libraries, including all debug or non-debug.
It's been a while since I tried working with characters between Fortran/C. I remember setting the "String Length Argument Passing" to "After all arguments" in the Fortran project.
It's been a while since I tried working with characters between Fortran/C. I remember setting the "String Length Argument Passing" to "After all arguments" in the Fortran project.

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