troubleshooting Question

Linker error: Undefined symbol _environ

Avatar of SimPilot
SimPilot asked on
CC++System Programming
7 Comments1 Solution1650 ViewsLast Modified:
As the title implies, I've got a confounding linker error.  First a bit of background:

I am developing in C on an old (15+ years) Unix platform running on Motorola hardware.  The computer is running a commercial flight simulator and I am writing a new software module from scratch that needs to be built into the simulator executable.  This module needs to grab data from the simulation and send it over the network to a server which will do a bunch of graphics processing.

I originally wrote the code and compiled it as a stand alone program that sent a few bytes of test data over the network, it compiled, linked, and ran with no problems.  

I modified the code so that instead of running as a stand alone program, it would run as a function in the simulation.  I added it to the Makefile and tried to compile/link, and I got the following error file from the linker:

** begin error file **
C-88000 1.8.6m1 Copyright (C) 1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993 Green Hills Software, Inc. All rights reserved.
undefined                  first referenced
 symbol                        in file
_inet_addr                          /home/9916dv/dvsrc/avionics/target/libeicas1.a
_socket                             /home/9916dv/dvsrc/avionics/target/libeicas1.a
_perror                             /home/9916dv/dvsrc/avionics/target/libeicas1.a
_exit                               /home/9916dv/dvsrc/avionics/target/libeicas1.a
_connect                            /home/9916dv/dvsrc/avionics/target/libeicas1.a
_modf                               /home/9916dv/dvsrc/avionics/target/libeicas1.a
_send                               /home/9916dv/dvsrc/avionics/target/libeicas1.a
ld fatal: Symbol referencing errors. No output written to /home/9916dv/MVME187.dvload/sim/dvload/SIMTASK32.LN

** end error file **

The file that is referenced, libeicas1.a, is the archive that my file was rolled up into.

After googling around I found the suggestion to link in the standard c library with the linker flag '-lc'.  I tried this and that solved the problems with the unrecognized socket functions, but now I get this error from the linker:

** begin error file **
C-88000 1.8.6m1 Copyright (C) 1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993 Green Hills Software, Inc. All rights reserved.
undefined                  first referenced
 symbol                        in file
_environ                            /lib/libc.a
ld fatal: Symbol referencing errors. No output written to /home/9916dv/MVME187.dvload/sim/dvload/SIMTASK32.LN

** end error file **

I googled everywhere I can find but can not find out what I should be doing about this error.  The man page for environ shows 'char ** environ' in the synopsis, but I'm not sure what to do with this.  I have tried adding it as a declaration at the top of my file, but to no avail.  

Can anyone provide insight as to this error and what to do to fix it?  Many thanks and accolades will be lavished upon you.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros