Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I avoid this error with setenv in C?

Tags:

c

posix

gcc

irix

First disclosure: I am not much of a C programmer. I am trying to compile a set of C and Fortran codes with much pedigree, using a Makefile to generate an executable for engineering computation. I am using gcc 4.7.1 on sgi Irix (6.5.30). During compilation of the main program, first I get a warning on 'Implicit declaration of function 'setenv'. Subsequently, after generating all the objective 'o' files, the compilation ends with an error :

ld32: Error 33: Unresolved data symbol "setenv"

Commenting out the single line where the 'setenv' is defined allows the compilation to succeed and generate the executable file. However the line with setenv is crucial to the program.

This led me to write a test code and confirm the same problem :

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
int main()
{
   setenv("FILE","/usr/bin/example.c",50);
   printf("File = %s\n", getenv("FILE"));
   return 0;
}

Based on all the suggestions I have found while googling here on stack exchange and other sites, I tried including different headers like

#define _POSIX_C_SOURCE

and

#define _GNU_SOURCE

before any #define statements. I have also tried compiling with -std=c99 as well as -D_XOPEN_SOURCE and -D_GNU_SOURCE with no luck.

I have also tried compiling the test program with Irix's native C compiler (cc and c99) and I get the same error:

Unresolved text symbol 'setenv'

Can someone please provide a helping hand on what else I should look for in my system and or environment variables in order to resolve this error?

like image 419
Kaushik Mallick Avatar asked Oct 05 '18 14:10

Kaushik Mallick


1 Answers

It indeed looks like IRIX libc does not support the setenv() command. You will have to rewrite it with putenv() like this:

putenv("FILE=/usr/bin/example.c");

See also the IRIX putenv() manpage. Looking for setenv() there does not show any hits, so I assume, this function is missing (note: IRIX 6.5.30 is from 2006)

like image 83
Ctx Avatar answered Oct 07 '22 18:10

Ctx