* * *

Author Topic: 'Undefined Symbol' Error when consuming FPC library in C on AIX (powerpc64)  (Read 1045 times)

danielcarcich

  • Newbie
  • Posts: 2
My goal is to get a very simple proof of concept FPC (3.0.4, powerpc64) library working with C (gcc 4.8.3) on an AIX 64-bit machine (7.1).

My FPC library consists of two files:

HelloWorldLib.lpr
Code: Pascal  [Select]
  1. library HelloWorldLib;
  2.  
  3. uses
  4.   HelloWorldFunctions;
  5.  
  6. exports
  7.   HelloWorld;
  8.  
  9. begin
  10. end.

HelloWorldFunctions.pas
Code: Pascal  [Select]
  1. unit HelloWorldFunctions;
  2.  
  3. interface
  4.  
  5. procedure HelloWorld; cdecl;
  6.  
  7. implementation
  8.  
  9. procedure HelloWorld; cdecl;
  10. begin
  11.   Writeln('Hello, world.');
  12. end;
  13.  
  14. end.

My C application is a very simple consumer:

helloworld.c
Code: [Select]
extern void HelloWorld(void);

int main()
{
  HelloWorld();
  return 0;
}

For compiling the library, I have tried many of the FPC arguments listed here: https://www.freepascal.org/docs-html/user/userap1.html. It successfully compiles a libHelloWorldLib.a archive file. E.g.

Code: [Select]
fpc HelloWorldLib.lpr -B -CN -l -O2 -MobjFPC
For compiling the C application I use the following command, and have tried multiple variations on this as well:

Code: [Select]
gcc -o hw helloworld.c -L. -lHelloWorldLib
I receive the following error message: "ld: 0711-317 ERROR: Undefined symbol: .HelloWorld". If I use "g++" instead of "gcc", I get: "ld: 0711-317 ERROR: Undefined symbol: .HelloWorld()".

If I use "dump -HTv libHelloWorldLib.a", I get nothing, which seems to indicate that there are no symbols in the archive.

I'd appreciate any assistance that can be provided. Thanks!

Phil

  • Hero Member
  • *****
  • Posts: 2653
I'd appreciate any assistance that can be provided. Thanks!

You might find this helpful:

https://macpgmr.github.io/MacXPlatform/PascalDynLibs.html


danielcarcich

  • Newbie
  • Posts: 2
Naturally after 2 days of struggling with this and finally making a post about it, I figure out what I'm missing:

I needed to add the "-maix64" flag to the gcc call. Tada! Sorry for wasting some space on this pleasant forum!

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus