Compilation mistake with a C and ASM programs

  • Follow


Hello,

I'm using visual studio 6.0 sp 5 with the processor pack.
I would like use a C variable with my C program but visual c giving me 
and unreconized symbol, and i don't know why :/

test.obj : error LNK2001: unresolved external symbol _toto
Debug/uuu.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

uuu.exe - 2 error(s), 0 warning(s)

I'm pasting my example :

1. I'm creating a visual studio Console project and i'm writting the 
folliwing code :

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

extern "C" void compute();
char *toto;
void main(void)
{

	int i;
	toto = ( char *) calloc (11, sizeof( char));

	compute();

	/*for (i = 0 ; i < 10 ; i++)
	{
		toto[i] = 'A'+i;
	}*/
	printf("%s",toto);
	
	//getch();
	free(toto);
	
}

2. The Asm program :

..586
..model flat,C

public compute
extrn toto:dword ; i tried to put extrn _toto:dword , extrn _toto : 
byte, extrn toto : byte, and i don't works :/
..data
zeroo dd 0

..code


compute proc


	mov esi, toto   ; idem for extrn , i tried _toto too
	mov eax,'A'
	xor ecx,ecx

_loop:
	mov byte ptr [esi],al
	inc ecx
	inc esi
	inc eax
	cmp ecx,10
	jne _loop


	

ret
compute endp


end

3. I'm setting up the asm file compilation directive  : Custom build : 
ml.exe -c -coff -Cx -Fo$(IntDir)\$(InputName).obj $(InputName).asm
and outputs : $(IntDir)\$(InputName).obj

Thanks you for your help, and please accept my apologize for my bad 
english :/ Have a nice day ;o)

Sincerly,

skweek

0
Reply skweek 2/24/2005 6:31:28 PM

Apart from its probably better to use EXTERNDEF with ML 6.15, I think
your problem is you are not making the C variable "todo" visible to the
asm procedure. My C is too rusty but you need something like PUBLIC for
the address of the todo string buffer as you must remember that the
MASM code is in a seperate module and has no way of accessing the
string address.

Looking at your code, I don't see why you don't just pass it as a
parameter to the module in assembler. It would solve these basic scope
issues.

Regards,

hutch at movsd dot com

0
Reply hutch 2/24/2005 7:48:24 PM


"skweek" <spamtrap@crayne.org> wrote in message 
news:cvkf5k$s08$1@biggoron.nerim.net...
> Hello,
>
> I'm using visual studio 6.0 sp 5 with the processor pack.
> I would like use a C variable with my C program but visual c giving me and 
> unreconized symbol, and i don't know why :/
>
> test.obj : error LNK2001: unresolved external symbol _toto
> Debug/uuu.exe : fatal error LNK1120: 1 unresolved externals
> Error executing link.exe.
>
> uuu.exe - 2 error(s), 0 warning(s)
>
> I'm pasting my example :
>
> 1. I'm creating a visual studio Console project and i'm writting the 
> folliwing code :
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <conio.h>
>
> extern "C" void compute();
> char *toto;
[...]

You are using the C++ language, not C, and there is a big difference when it 
comes to naming. C++ name mangling means that toto will not be emitted as 
_toto. I don't know the syntax rules on extern, but this seems to work for 
me:

extern "C"
{
 char *toto;
};

That should cause toto to have the name _toto instead of 
_toto?@somereally@l??ongstr?ingthate?ncodes##typeinf@ormation.

-Matt 

0
Reply Matt 2/24/2005 11:21:07 PM

> > extern "C" void compute();
> > char *toto;
> [...]
> 
> You are using the C++ language, not C, and there is a big difference when it
> comes to naming. C++ name mangling means that toto will not be emitted as
> _toto. I don't know the syntax rules on extern, but this seems to work for
> me:
> 
> extern "C"
> {
>  char *toto;
> };

That's okay, and there are another syntax to write:

Solution 1:
	extern "C" char *toto;

Solution 2:
extern "C"
{
	void compute();
	char *toto;
}


If you use 'extern "C"' so often, these macros will help:

#ifdef __cplusplus
	#define BEGIN_EXTERN_C	extern "C" {
	#define END_EXTERN_C	}
#else
	#define BEGIN_EXTERN_C
	#define END_EXTERN_C
#endif

This is the way that compilers' header files do.

========================================================================
(Mr.) IIJIMA Hiromitsu,                  mailto:delmonta@ht.sakura.ne.jp
           aka Delmonta            http://www.ht.sakura.ne.jp/~delmonta/


There are more than one ways for doing the same thing.    --- Larry Wall

0
Reply IIJIMA 2/25/2005 1:59:07 AM

IIJIMA Hiromitsu a écrit :
>>>extern "C" void compute();
>>>char *toto;
>>
>>[...]
>>
>>You are using the C++ language, not C, and there is a big difference when it
>>comes to naming. C++ name mangling means that toto will not be emitted as
>>_toto. I don't know the syntax rules on extern, but this seems to work for
>>me:
>>
>>extern "C"
>>{
>> char *toto;
>>};
> 
> 
> That's okay, and there are another syntax to write:
> 
> Solution 1:
> 	extern "C" char *toto;
> 
> Solution 2:
> extern "C"
> {
> 	void compute();
> 	char *toto;
> }
> 
> 
> If you use 'extern "C"' so often, these macros will help:
> 
> #ifdef __cplusplus
> 	#define BEGIN_EXTERN_C	extern "C" {
> 	#define END_EXTERN_C	}
> #else
> 	#define BEGIN_EXTERN_C
> 	#define END_EXTERN_C
> #endif
> 
> This is the way that compilers' header files do.
> 
> ========================================================================
> (Mr.) IIJIMA Hiromitsu,                  mailto:delmonta@ht.sakura.ne.jp
>            aka Delmonta            http://www.ht.sakura.ne.jp/~delmonta/
> 
> 
> There are more than one ways for doing the same thing.    --- Larry Wall
> 
Thanks you very much for your help :)

Sincerly

Skweek

0
Reply skweek 2/25/2005 7:15:45 PM

Matt a �crit :
> "skweek" <spamtrap@crayne.org> wrote in message 
> news:cvkf5k$s08$1@biggoron.nerim.net...
> 
>>Hello,
>>
>>I'm using visual studio 6.0 sp 5 with the processor pack.
>>I would like use a C variable with my C program but visual c giving me and 
>>unreconized symbol, and i don't know why :/
>>
>>test.obj : error LNK2001: unresolved external symbol _toto
>>Debug/uuu.exe : fatal error LNK1120: 1 unresolved externals
>>Error executing link.exe.
>>
>>uuu.exe - 2 error(s), 0 warning(s)
>>
>>I'm pasting my example :
>>
>>1. I'm creating a visual studio Console project and i'm writting the 
>>folliwing code :
>>
>>#include <stdio.h>
>>#include <stdlib.h>
>>#include <conio.h>
>>
>>extern "C" void compute();
>>char *toto;
> 
> [...]
> 
> You are using the C++ language, not C, and there is a big difference when it 
> comes to naming. C++ name mangling means that toto will not be emitted as 
> _toto. I don't know the syntax rules on extern, but this seems to work for 
> me:
> 
> extern "C"
> {
>  char *toto;
> };
> 
> That should cause toto to have the name _toto instead of 
> _toto?@somereally@l??ongstr?ingthate?ncodes##typeinf@ormation.
> 

Thanks you very much :))

I doesn't know this concept of name mangling :/ Are you more information 
   which can giving more information name notation :

_toto?@somereally@l??ongstr?ingthate?ncodes##typeinf@ormation. ?

I'm solving my problems thanks to you. :)))

Sincerly

Skweek

0
Reply skweek 2/25/2005 7:15:52 PM

hutch-- a �crit :
> Apart from its probably better to use EXTERNDEF with ML 6.15, I think
> your problem is you are not making the C variable "todo" visible to the
> asm procedure. My C is too rusty but you need something like PUBLIC for
> the address of the todo string buffer as you must remember that the
> MASM code is in a seperate module and has no way of accessing the
> string address.
> 
> Looking at your code, I don't see why you don't just pass it as a
> parameter to the module in assembler. It would solve these basic scope
> issues.

I'm trying to rewrite an old program of my firm. I looking for the best 
compromise in my situation to have a good code the most portable. And my 
choice is to call a pointer which will be allocated by a 
(malloc/calloc), and this pointer will be modified for critical 
procedure via a assembly code.

I have solving my problem via extern "C" type *myvar; and on asm file :
..model flat,c
..586
..data
extrn myvar:dword
..code
;the program
end

Thanks for all :))

Sincerly

skweek

0
Reply skweek 2/25/2005 7:15:56 PM

6 Replies
116 Views

(page loaded in 0.153 seconds)

Similiar Articles:













7/22/2012 9:18:05 AM


Reply: