?
Solved

Linker error: Undefined symbol _environ

Posted on 2007-07-30
7
Medium Priority
?
1,572 Views
Last Modified: 2013-12-26
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.
0
Comment
Question by:SimPilot
  • 3
  • 3
7 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 19592788
Can you show your link command ?

_environ will be provided on program start. So, I assume that your linker command has a problem. Did you base yourself on the linker command used for the simulator software ?
0
 
LVL 86

Accepted Solution

by:
jkr earned 1500 total points
ID: 19592798
>>I have tried adding it as a declaration at the top of my file, but to no avail.  

How did you try that? A

char** environ = NULL;

usually should solve the problem (yet might not be the final solution).
0
 

Author Comment

by:SimPilot
ID: 19592849
Yes, my link command came from adding '-lc' to the link command already used in the config file that builds the project.  After my addition of '-lc' the link command looks like this:

LDFLAGS='-L/home/1334/lib -lethero -L/home/9916dv/dvsrc/avionics/target -lefis -leicas1 -leicas2 -leicas1 -lcmn -lnsl -lc'

That is included in a config file which is read by some shell scripts which grab the contents of LDFLAGS.  The efis and eicas libraries are archives that are project specific.  I have no idea why eicas1 is included twice, but it seems to get angry if I remove one of them.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:Infinity08
ID: 19592872
>> After my addition of '-lc' the link command looks like this:

Those are just the link flags ... But what's the command used for linking ? (ie. the command where LDFLAGS is used).
What compiler are you using ?


>> I have no idea why eicas1 is included twice, but it seems to get angry if I remove one of them.

Probably because of circular dependencies of some sort ... That shouldn't be the problem.
0
 

Author Comment

by:SimPilot
ID: 19594457
I can't find the line in the myriad of shell scripts that actually calls the linker, but I know that it is ld, and the compiler is the Green Hills compiler, circa 1990ish.
0
 

Author Comment

by:SimPilot
ID: 19594482
> char** environ = NULL;
>usually should solve the problem (yet might not be the final solution).

jkr, this solution worked for me.  I did not try setting environ to NULL as the few web pages I found regarding its use said that altering its value can be dangerous since you can overwrite other stuff that got passed in with it.  I'm not entirely sure what it does or how that fix worked, but it did, and since this is on a time crunch that's what I'm happy about.  

Thanks jkr and Infinity08 for your help.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 19594516
>> but I know that it is ld, and the compiler is the Green Hills compiler, circa 1990ish.

Yes, I have seen this kind of problem when using ld to link instead of the compiler. So, if you're still interested in fixing this problem, then try linking with the compiler instead of ld.


>> I'm not entirely sure what it does or how that fix worked, but it did, and since this is on a time crunch that's what I'm happy about.

I would seriously test before using this as a solution ... You're basically overriding the environ value. And some code depending on that might not like that.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question