flat assembler
Message board for the users of flat assembler.

Index > Main > problems with extrn/public

Author
Thread Post new topic Reply to topic
chorus



Joined: 16 Mar 2004
Posts: 23
chorus
Hello,
I'm trying to call some ASM code from C++ and it isn't working. I've checked through the forum and couldn't find the proper way of doing this. The C++ program calls the function StringLength from my asm library and then outputs the length of a (fixed) string.

The asm source looks like this (note that this is for linux - but it shouldn't matter):

Code:
;strlen.asm

format ELF
include "%mylib%/linux.inc"            ;just loads up proc/end macro, etc

public StringLength as "_StringLength"

proc StringLength,lpString
      enter
      push ebx
      mov ebx,[lpString]
      or eax,-1
@@:
      inc eax
      cmp byte [ebx+eax],0
      jne @B
      pop ebx
      return
endp
    


The C++ code looks like this:

Code:
//say.cpp

#include <iostream>

using namespace std;
extern "C" int StringLength (char *);

int main()
{

  char *OutputString = "This is the wrong string. You blew it.\n";

  printf("The string length is %d bytes.\n",StringLength(OutputString));
  return (0);
}
    


I compile fasm with a simple fasm strlen.asm and then compile the main proggy with g++ say.cpp strlen.o -o say. But I keep getting this from g++:

Quote:

: undefined reference to `StringLength'


I'm sure I'm using extern and public incorrectly, but I'm not sure what I'm missing. Any advice is much appreciated

Thanks
--Chorus
Post 06 Sep 2004, 01:03
View user's profile Send private message Reply with quote
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer
In linux, elf files don't have an underscore.

So

public StringLength as "_StringLength"

Should be simply

public StringLength
Post 06 Sep 2004, 01:21
View user's profile Send private message Reply with quote
chorus



Joined: 16 Mar 2004
Posts: 23
chorus
Haha... so simple....

Thanks Smile

--Chorus
Post 06 Sep 2004, 02:28
View user's profile Send private message Reply with quote
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer
Hit me the first time too Smile
Post 06 Sep 2004, 14:35
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.