internal datas uninitialized in imported lib are not recognized

Started by beatrix, February 04, 2009, 07:53:45 PM

Previous topic - Next topic

beatrix

Hi,

I try to link a library coded in C with a small program coded in GoAsm syntax. This library is using internal variables that I only defined without any initialization like this :
long MyVar1;
It seems that GoLink 0.26.9e does not like that.
QuoteGoLink.Exe Version 0.26.9e - Copyright Jeremy Gordon 2002/9-JG@JGnet.co.uk

Error!
The following symbols were not defined in the object file or files:-
MyVar1

If I init this variable like this :
long MyVar1 = 0;
then, there is no more trouble.

jorgon

Hi Beatrix

I have no idea why this is happening, maybe someone with more "C" experience would know?

Anyway just to let you know that it may be easier to mix "C" code with GoAsm code with the latest GoLink (version 26.10 beta2) using the /mix switch - see
http://www.masm32.com/board/index.php?topic=10770.0.

Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

beatrix

thank you but I have the same problem with the 0.26.10b2 (with the /mix swith and without it). In the example that is mixing C code (compiled with Pelles C) and GoAsm code, the main program is in C and the library imported is coded in GoAsm. I am in the other situation, main program in GoAsm and lib in C :)

jorgon

Are you able to post the files concerned so that we can see the difference in the way the symbol MyVar1 is being put in the object file created by Pelles C between the two types of declaration?

Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

beatrix

yes, off course. I just made a small example that illustrate my pb.

[attachment deleted by admin]

jorgon

Beatrix

Thanks for posting the files.  Looking at these with Wayne Radburn's excellent PEView available from http://www.magma.ca/~wjr, I can see that the symbol _MyVar1 is in the symbol table of the object file created from the MyLib.c file.  However, it has not been allocated a section, which means that the compiler has regarded it as referenced but not declared.

This is why GoLink is not finding it as a declared (defined) symbol.

Perhaps in "C" you have to initialise a data label before it is regarded as declared?

Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

beatrix

ok, I read my book about programming in C and I found something interesting. In fact, you don't have to intialise variables. You just have to declare them, it is enough...BUT, there is something specific if your program is build with several code sources. You can use 2 keywords "extern" and "static" to specify if your declared variable is accessible for everyone or only for the library.
So, if I write :
static long MyVar1;
MyVar1 becomes a private variable that is not visible (can only be used by the library itself) and so...GoLink does not shout !
If we only write :
long MyVar1;
I think (I am not sure) that MyVar1 is considered as a global variable and so, can be used by everybody. In that case, GoLink cry cry and cry again :)

I will fix that by adding the "static" keyword but that's weird, masm, nasm and fasm does not have this pb. Thank you Jeremy.

jorgon

Ok Beatrix

Thanks for the report.
It does seem possible that GoLink is missing some symbols created by a "C" compiler which it ought to deal with.
I'll look into this and come back to you.

Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

jorgon

Hi Beatrix

I have now added support to GoLink for "common symbols" as in your file, when the /mix switch is used see http://www.masm32.com/board/index.php?topic=10770.

Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

beatrix

hum, sorry for this message, maybe I forgot something. I link my lib like that :

QuoteGoLink /console /mix %name%.obj MyLib.lib kernel32.dll msvcrt.dll

and I have this message :

QuoteGoLink.Exe Version 0.26.10 beta3- Copyright Jeremy Gordon 2002/9-JG@JGnet.co.uk

Error!
The following symbol was not defined in the object file or files:-
MyVar1
Output file not made

jorgon

I used the following command line with GoLink 0.26.10 beta3 and your file MyLib.obj which you sent earlier.

GoLink /console /mix MyLib.obj kernel32.dll msvcrt.dll

This found MyVar1 ok (although there is a "no entry point" warning).

GoLink ignores lib files, but even with that included in the command line it still finds MyVar1!

So if you are still getting this error, I don't think we can be using the same MyLib.obj files.
Would you mind posting it again?


Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

beatrix

hmm...strange. Here is the example.

[attachment deleted by admin]

jorgon

Thanks for posting your file again but I get the same result as I got before!
The two files you posted (MyLib.obj) are the same, except for the date.
GoLink 0.26.10 beta3 is finding MyVar1 and is making the exe on my machine, albeit with the "Start warning".

I have always thought there is an explanation for everything, but maybe its time to see the light.

Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

beatrix

QuoteGoLink ignores lib files

haaa, that's it ! I had partially read your previous post... ok, ok ! if I link MyLib.obj, it is working perfectly ! If I link MyLib.lib, I still have the problem. Sorry, GoLink 0.26beta3 works perfectly now. We just have to use the object file, not the .lib.

jorgon

Thanks for letting us know Beatrix.
I'll probably have to postpone my conversion, although I still don't understand why GoLink was looking for MyVar1 in the first place, since the lib file would be ignored and so the only file involved was the object file.

Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)