Valhalla Legends Forums Archive | Assembly Language (any cpu) | [FASM] Error: Symbol already defined

AuthorMessageTime
Yegg
I started really studying x86 asm recently and decided I would use FASM. I tried writing a basic console hello world application. I'll start by showing my code:

[code]format PE console
entry start

include 'include\win32ax.inc'

section '.code' code readable executable
  start:
        invoke AllocConsole
        invoke GetStdHandle, STD_OUTPUT_HANDLE
        mov [_outhandle], eax
        invoke GetStdHandle, STD_INPUT_HANDLE
        mov [_inhandle], eax
        invoke WriteConsole, [_outhandle], _msg, 13, _written, 0
        invoke ReadConsole, [_inhandle], _char, 1, _read, 0
  finish:
        invoke ExitProcess, 0

section '.data' data readable writeable
  _outhandle    dd  ?
  _inhandle    dd  ?
  _written      dd  ?
  _read        dd  ?
  _char        db  ?
  _msg          db  'Hello, world.'

section 'idata' import data readable writeable
  library kernel, 'KERNEL32.DLL'

  import kernel,\
        AllocConsole, 'AllocConsole',\
        GetStdHandle, 'GetStdHandle',\
        WriteConsole, 'WriteConsoleA',\
        ReadConsole, 'ReadConsoleA',\
        ExitProcess, 'ExitProcess'[/code]

What happens is when I try to assemble this code, I get the following error message:

[quote]Error: symbol already defined.[/quote]

It tells me that the error occured on the following instruction:

[code]WriteConsole dd RVA _label?000067F[/code]

First off, I really don't know what the above (the last text in the code tags) means. When the error dialog shows up, the following code is highlighted:

[code]import kernel,\
        AllocConsole, 'AllocConsole',\
        GetStdHandle, 'GetStdHandle',\
        WriteConsole, 'WriteConsoleA',\
        ReadConsole, 'ReadConsoleA',\
        ExitProcess, 'ExitProcess'[/code]

The above code is apparently the source of the error, located inside my program's source code (hello_world.asm). However, there are two sources of error. My source code (hello_world.asm) and import32.inc. The line of import32.inc which contains the source of error is line 45 which contains the following code:

[code]label dd RVA _label[/code]

I'm not entirely sure if the above is necessary for you to know or not.

Anyways, I'm not really sure what causes this error. If I decide not to define WriteConsole, I get the same type of error message only for ReadConsole instead. If I remove the definition for ReadConsole, it tells me that WriteConsole (and eventually ReadConsole) is not defined.

I would greatly appreciate help with this issue. I'd be glad to provide more information if that is necessary.

Update: I changed a few things. The program now can be compiled into a normal executable, however it will not run so it seems. The few things I changed were:

I changed
[code]include 'include\win32ax.inc'[/code]
to
[code]include 'include\win32a.inc'[/code]
I don't think this had any real effect.

I noticed a small problem where I wrote
[code]section 'idata' import data readable writeable[/code]
I left out the period (.) after the first apostrophe in 'idata'. This was changed into '.idata'.

I changed the import data section's code to:

[code]section '.idata' import data readable writeable
  library kernel, 'KERNEL32.DLL'

  include 'include\api\kernel32.inc'[/code]

This seems to be the main cause for removing the error messages I was receiving earlier. I am still at work trying to get the application to output text to the console. I'll keep this post updated, and I'm still looking for any possible help.
November 9, 2006, 11:09 PM
Kp
Now that you have it assembled and presumably runnable, run it under a debugger to find out what happens when it calls WriteConsole.
November 10, 2006, 2:07 AM
Yegg
[quote author=Kp link=topic=16015.msg161072#msg161072 date=1163124463]
Now that you have it assembled and presumably runnable, run it under a debugger to find out what happens when it calls WriteConsole.
[/quote]

Thanks for the help. I was getting ready to go ahead and try this, however I started to try and figure out another problem I was working on. The next day I assembled this same code and the program worked just fine. I'm still unsure of what caused it to fail the first time.
November 11, 2006, 1:07 AM

Search