1748289 Members
3169 Online
108761 Solutions
New Discussion юеВ

Re: linker problem?

 
Moiz Khambaty
Occasional Contributor

linker problem?

I have created a simple Hello World program given below :

#include
void hello()
{
rintf("Hello World");
}

Here instead of printf I have purposfully put an error namely "rintf"

Now I compiled this code using the comand
/opt/ansic/bin/cc -c +Z -o temp.o temp.c

After compilation I created a library libhello.sl containing the object file created above using the command

/opt/ansic/bin/cc -b temp.o -o libhello.sl

Now the linker is supposed to complain saying "unresolved symbol" for "rintf" but it does not do so. When i use this sl with a sample program still it does not complain about the symbol rintf while compilation. But when I run the sample application, it gives:
/usr/lib/dld.sl: Unresolved symbol rintf (code) from ./libhello.sl
ABORT instruction (core dumped)

Thankyou
Moiz Khambaty
5 REPLIES 5
Saravanan_6
Advisor

Re: linker problem?

U misspelled the printf as rintf. That is the cause for unsatisfied symbol.
Muthukumar_5
Honored Contributor

Re: linker problem?

hai Moiz,

After doing compilation as cc -c <..> we must have to do link to execute the particular object file. So It is not in the linked format.

During the shared library creation it is creating the shared library file using the non-linked temp.o file

So during the application usage on the sl only it is getting linked and getting compiled as,

/usr/lib/dld.sl: Unresolved symbol rintf (code) from ./libhello.sl
ABORT instruction (core dumped)

You can try as,

/opt/ansic/bin/cc temp.c -o temp.o
Some warning will be there from compiler ( -c will supress them and execution file a.out)

If you do it successfully without error then use cc -b temp.o -o libhello.sl


You will get more problem's for your try as

#include
void hello()
{
rintf("Hello World");
}

as
1> no main..
2> return type etc

Regards
Muthu
Easy to suggest when don't know about the problem!
Saravanan_6
Advisor

Re: linker problem?

Oh sorry I failed to notice

"Here instead of printf I have purposfully put an error namely "rintf" "
ranganath ramachandra
Esteemed Contributor

Re: linker problem?

the linker does not report unsats from shared libraries by default. it will definitely not error out. if you want warnings, you can get them with the +vshlibunsats linker option.
 
--
ranga
[i work for hpe]

Accept or Kudo

ranganath ramachandra
Esteemed Contributor

Re: linker problem?

+vshlibunsats will give you warnings only when linking the shared library.

+vallunsats when linking an executable will list unsats in the shared libraries in the link line.

now by unsats i mean symbols not resolved but required to be resolved, as far as the linker can find out from the direct calls made in the modules being linked.

when building an executable, the linker expects all symbols to be resolved (unless you say +allowunsats). here the requirement for resolving all referenced symbols is driven/ensured by the compiler specifying 'main' as an unsat in the link line (add -v to compile line to see that). so an unresolved symbol is an error in that case.

when building a shared library, the linker actually allows for unsats. so an unresolved symbol will never be an error, it will be a warning at best.
 
--
ranga
[i work for hpe]

Accept or Kudo