lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Philippe Verdy once stated:
> Le dim. 25 nov. 2018 à 02:23, Sean Conner <sean@conman.org> a écrit :
> 
> > It was thus said that the Great Philippe Verdy once stated:
> > > Le sam. 24 nov. 2018 à 23:20, Sean Conner <sean@conman.org> a écrit :
> >         % uname
> >         Linux
> >         % cc    -c -o main.o main.c
> >         % cc    -c -o myfunc2.o myfunc2.c
> >         % cc -shared -fPIC -o func.ss func.c
> >         % ar rv libfuncall.so func.ss
> >         % ar: creating libfuncall.so
> >         % a - func.ss
> >         % cc  -Wl,-rpath,/tmp/foo -o smain2 main.o myfunc2.o libfuncall.so
> >         % ./smain2
> >         Hello from main
> >                 Hello from func1
> >                         Hello from myfunc2
> >                 Back to func1
> >         Back to main
> >                         Hello from myfunc2
> >         Back to main
> >
> >   Happy now?
> 
> That's what I wanted. And demonstrates what I wanted to show: this is the
> only portable and expected behavior !

  I am confused.  

  Here's the Windows example.  This has func1() and func2() in separate C
files that are compiled, and both files are used to create the shared
library:

        >cl /c main.c
        >cl /c func1.c
        >cl /c func2.c
        >cl /c myfunc2.c
        >link /dll /out:mylib.dll func1.obj func2.obj
          Creating library mylib.lib and object mylib.exp
        >link /out:main.exe main.obj myfunc2.obj mylib.lib
        >main
        Hello from main
                Hello from func1
                        Hello from func2 ********
                Back to func1
        Back to main
                        Hello from myfunc2
        Back to main

Look closely at the line marked with '********' (which I just added by hand,
to the output).  Notice the function that was called---func2().  NOT
myfunc2().  func2().  

  Here's the same, but under Linux:

	% cc    -c -o main.o main.c
	% cc    -c -o myfunc2.o myfunc2.c
	% cc -shared -fPIC -o func1.ss func1.c
	% cc -shared -fPIC -o func2.ss func2.c
	% cc -shared -o libfunc.so func1.ss func2.ss
	% cc  -Wl,-rpath,/tmp/foo -o smain4 main.o myfunc2.o libfunc.so 
	% ./smain4
	Hello from main
	        Hello from func1
	                Hello from myfunc2 ********
	        Back to func1
	Back to main
	                Hello from myfunc2
	Back to main

Again, look closely at the line marked with '********'.  Notice the function
that was called---myfunc2().  NOT func2().  myfunc2().

Do you notice the difference between the two?

BOTH examples used shared libraries.  So what is the "portable and expected"
answer?  What should the output be for shared libraries?

  -spc (Before this, I would have said the Linux version, but I was not familiar
	with Windows, so I was wrong in that regard)