Unresolved External Symbol _getenv_ USE IFPORT Link Error For Application Porting From UNIX To Win32

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,

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.

Number of View :2072

Tags: , ,

  1. No comments yet.

Content Protected Using Blog Protector By: PcDrome.

Mahol Dot Org is Stephen Fry proof thanks to caching by WP Super Cache