- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In summary, I have a C++ *.exe application which depends on a Fortran *.lib and a C++ *.lib that are compiled in the same solution as the *.exe.
The code was working fine stepping through in Debug mode, however when I went to port to a Release mode version all heck broke loose.
The first problem I encountered was "error LNK2001: unresolved external symbol _WinMain@16 MSVCRT.lib".
I resolved this by adding the following code to the main *.cpp:
#ifdef CONSOLE
#pragma comment(linker, "/subsystem:console")
#else
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
This got me through compilation and linkage and created an *.exe file. Then upon execution I encountered an unhandled exception in the code.
I don't understand why the code worked fine stepping through in Debug then fails in Release. I checked all the options and when the code was working in Debug the subsystem was even set to Console. What's going on here? I know that all of the variables are mapped correctly across the C++/Fortran interfaces. I verified program values and results obtained using the interface in Debug versus a standalone Fortran project, so the calculations are working properly.
For reference I've attached the main blocks of three projects in the solution:
Cpp *.exe
#include "stdafx.h"
#pragma comment(lib,"CppCode.lib")
#pragma comment(lib,"FortranCode.lib")
#ifdef CONSOLE
#pragma comment(linker, "/subsystem:console")
#else
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
extern "C" {
void FORLINK(double *in, double *figin, double *out);
}
int main(int argc, char* argv[])
{
....
}
Fortran *.lib
SUBROUTINE FORLINK(in, figin, out)
....
intA=CPPEX(ab,cd)
....
END SUBROUTINE
Cpp *.lib
extern "C" int CPPEX(int ab, char *cd)
{
...
return intB;
}
Link Copied
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page