Was getting below link errors when compiling application with fortran files and c files. Was using ifort.exe and cl.exe to compile and link.
error LNK2019: unresolved external symbol _getenv_ referenced in function xyz
error LNK2001: unresolved external symbol _getenv_
Usage in fortran file, this is call to getenv
CALL GETENV (“LIB”,libname)
After few hours of google got different solutions, saying using assume:nounderscore flag in compilations.
tried with assume:underscore , assume:nounderscore and assume:no2underscore
And use ifport.lib and ifcore.lib but did not got the error resolved.
If this error was happen to come from .c file then solution is direct ie use stdlib.h include file.
Finally got the Solution
Add these two lines in your FORTRAN file,
USE IFPORT
USE IFCORE
and compile again the error goes away.
Some description about USE
The USE statement gives a program unit accessibility to public entities in a module.
getenv and _putenv use the copy of the environment pointed to by the global variable _environ to access the environment. getenv operates only on the data structures accessible to the run-time library and not on the environment segment created for the process by the operating system.
In a program that uses the main function, _environ is initialized at program startup to settings taken from the operating system’s environment.
Happy application porting from UNIX to win32.
No related posts.
Tags: fortran, link errors, win32
This entry was posted on Tuesday, May 25th, 2010 at 12:06 am and is filed under Unix2Win32_Porting. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.