Difference between Unix and Linux for resolving symbols


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Difference between Unix and Linux for resolving symbols
# 1  
Old 10-17-2012
Difference between Unix and Linux for resolving symbols

I came across a difference between Unix and Linux, when it comes to resolving the symbols from the libs.

consider the following code segments...

Code:
$ cat call1.c
#include <stdio.h>
int a1;
extern int a3;
void  prnt_a3()
{
  printf("\n%d\n",a3);
}

$ cat test.c
#include <stdio.h>
extern int a1;
int  main()
{
  int a2=20;
  printf("\n%d\n",a1);
  return 0;
}

Highlights are...

* a1 is defined in call1 and is being referenced in test.c and is being used also
* a3 is referenced to in test.c and is not defined anywhere. It is being used but in a dead function prnt_a3

I am running it as

Code:
cc -g -c test.c call1.c
ar q lib.a call1.o
cc -g -o test test.o lib.a

The executable gets build in HP Unix bit in Linux, it fails saying

Code:
call1.c:6: undefined reference to `a3'
collect2: ld returned 1 exit status

I don't know the concept/rationale behind the same. Smilie
HPUx just refers to the data definitions and it doesn't bother about the functions unless there is atleast 1 function being used from that routine (in which case, HP also gives error) ???

If anyone can suggest some reading material for the same, it'll also be great.

Thanks...

Last edited by Scott; 10-17-2012 at 12:42 PM.. Reason: After almost 5 years, you should know to use code tags :)
# 2  
Old 10-17-2012
Quote:
The executable gets build in HP Unix bit in Linux, it fails saying
A binary built on HP (HP-UX?) will probably not run on a Linux box.
# 3  
Old 10-17-2012
The executable will not run for sure.. as it is a C code.

The issue is that Linux is not able to build the executable for this and Unix is able to.

So, there is a difference between how Unix and Linux handle this scenario.

I am trying to understand that.
# 4  
Old 10-17-2012
Quote:
Originally Posted by snowline84
So, there is a difference between how Unix and Linux handle this scenario.

I am trying to understand that.
First off, it has often been said and i will say it again: "Unix" is not an operating system, but a trademark. A system is "Unix", because its manufacturer bought the license to bear this trademark. "Linux" (to be precise: its manufacturers) did not purchase anything (mostly because there is no money to do so involved in Linux) and this is the only reason "Linux" is not a "Unix", but only "unixlike". This is about the same difference as "sparkling wine" versus "champagne": there is none. "Champagne" is the sparkling wine produced in the french area called Champagne, but that's it. You could create a sparkling wine which is absolutely identical to champagne - you would still not be allowed to call it "champagne" it you don't do so in the Champagne (and probably meet some other legalities too), but that would be about it.

The only real standard of any value is the POSIX standard. Linux is in most regards, AFAIK, compatible against this OS blueprint and so is HP-Ux (to which extent they actually conform i don't know - it is not the point of the argument).

Having said this: the real difference you perceive in your example above is probably the difference in the respective compiler suits. Try "gcc" in both environments (i suppose the HP-Ux compiler is not available in a Linux version) and probably the differences will vanish.

I hope this helps.

bakunin
# 5  
Old 10-17-2012
No there is no difference between the way unix and linux resolve symbols...the thing you are seeing is the default compilation mode in hpux is c89 while in linux it is c99 which is far more stricter than c89. In fact you will get the same error if you switch the default compilation mode in hpux to c99 by adding the following switch to your command line...
Code:
cc -AC99 <blah blah blah>

Quote:
Originally Posted by snowline84
I came across a difference between Unix and Linux, when it comes to resolving the symbols from the libs.

consider the following code segments...

Code:
$ cat call1.c
#include <stdio.h>
int a1;
extern int a3;
void  prnt_a3()
{
  printf("\n%d\n",a3);
}

$ cat test.c
#include <stdio.h>
extern int a1;
int  main()
{
  int a2=20;
  printf("\n%d\n",a1);
  return 0;
}

Highlights are...

* a1 is defined in call1 and is being referenced in test.c and is being used also
* a3 is referenced to in test.c and is not defined anywhere. It is being used but in a dead function prnt_a3
prnt_a3 is not a dead function...it is very much live and it is supposed to print an unallocated and undefined variable a3 which is an error...there is no difference in its treatment when it comes to unix or linux...
Quote:
Originally Posted by snowline84
I am running it as

Code:
cc -g -c test.c call1.c
ar q lib.a call1.o
cc -g -o test test.o lib.a

The executable gets build in HP Unix bit in Linux, it fails saying

Code:
call1.c:6: undefined reference to `a3'
collect2: ld returned 1 exit status

Even thogh hpux generates an a.out file yet that file isnt executable...did you even try to run the a.out file produced from the compilation...on my hpux box it says it cannot execute which is true as the compilation wasnt complete and so a load module wasnt generated. Linux is somewhat smarter and gives a linker error and stops there.
Quote:
Originally Posted by snowline84
I don't know the concept/rationale behind the same. Smilie
HPUx just refers to the data definitions and it doesn't bother about the functions unless there is atleast 1 function being used from that routine (in which case, HP also gives error) ???

If anyone can suggest some reading material for the same, it'll also be great.

Thanks...
Isnt function and routine the same thing so state your problem clearly...
This User Gave Thanks to shamrock For This Post:
# 6  
Old 10-17-2012
Hi Shamrock,

I tried to use the -AC99 option in HP-Ux. the behaviour is same as cc. There was no error thrown.

In my initial attempts also, the executable was getting generated (which executable permission and I am able to run them).

And I used the term routine for the file.
So, I was calling test.c one routine and call1.c another. Sorry if I created confusion over there Smilie

Thanks...
# 7  
Old 10-18-2012
Quote:
Originally Posted by snowline84
Hi Shamrock,

I tried to use the -AC99 option in HP-Ux. the behaviour is same as cc. There was no error thrown.
This shouldnt be happening...what is the version of your hpux box and also the C compiler you are using.
Quote:
Originally Posted by snowline84
In my initial attempts also, the executable was getting generated (which executable permission and I am able to run them).
Can you post the output you are getting from that executable...
Quote:
Originally Posted by snowline84
And I used the term routine for the file.
So, I was calling test.c one routine and call1.c another. Sorry if I created confusion over there Smilie

Thanks...
Alright makes sense...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Difference between UNIX and Linux

hi experts please tell me the real difference between unix and linux at kernel structure (1 Reply)
Discussion started by: linurag
1 Replies

2. Red Hat

Difference in conflict resolving between yum and rpm installs

Hi Guys, I am trying to test installation of a local rpm to my RHEL5 server. I am expecting it to fail as a previous version of the same package name exists. On using rpm -i this behaves as expected but yum install does not pick up the conflict. Here is the element of my SPEC file with the... (5 Replies)
Discussion started by: gazza-o
5 Replies

3. UNIX for Dummies Questions & Answers

difference between unix and linux

Hi I am new to linux I have dout waht is the difference between UNIX and LINUX Is there any soft for insatallation for UNIX OS Thanks (0 Replies)
Discussion started by: sanjaya
0 Replies

4. Shell Programming and Scripting

difference in unix vs. linux sort

Hi, I am using some codes that have been ported from unix to linux, and now the sorting no longer results in the desired ordering. I'm hoping to find a way to mimic the unix sort command in linux. The input file is structured the following: $> cat file.txt... (6 Replies)
Discussion started by: aj.schaeffer
6 Replies

5. AIX

difference between AIx and Linux and Unix

Sir , Can any body explain the difference between linux , Unix and AIx on command Reference all the command on AIx and unix is same or not please reply (2 Replies)
Discussion started by: arif185
2 Replies

6. UNIX for Advanced & Expert Users

What is the difference between Unix & linux

:confused: Hi All Can anyone help me in finding the answer of the question mentioned below. What is the difference between Unix & linux ? Thanks in Advance to all CSaha (1 Reply)
Discussion started by: csaha
1 Replies

7. UNIX for Dummies Questions & Answers

Difference between UNIX and Linux

OK, I've used various versions of UNIX(Solaris, HPUX, etc..) over the years. Now the organization I work for is leaning towards more Linux based systems(Redhat, Suse, etc..) I do see differences in in comands and how to accomplish basic adminstration, but nothing mind blowing. So, what is it... (5 Replies)
Discussion started by: pbonilla
5 Replies

8. UNIX for Dummies Questions & Answers

difference between unix and linux?

Ok, I'm confused. Can someone answer these (stupid) questions please for me? 1. What is the difference between unix and linux? 2. Is FreeBSD a unix distribution? 3. If not, then what is Unix? I actually gone to Unix.com because I thought this is it's official website where I could download... (1 Reply)
Discussion started by: RellioN
1 Replies

9. Programming

Difference Between Unix and Linux Envoriment

This may/may not be a long answer to a short question. I am learning the C programming language at home.I have seen some good books on the UNIX programming enviroment.However, there were a few books that hinted towards the Linux programming enviroment.Is there any difference between the two as... (1 Reply)
Discussion started by: perrylx
1 Replies
Login or Register to Ask a Question