Recent

Author Topic: Error when trying to use an external C library  (Read 2522 times)

gwiesenekker

  • New Member
  • *
  • Posts: 13
Error when trying to use an external C library
« on: June 28, 2013, 08:32:35 am »
Hi,

I am trying to call an external C function:

const
  ext = 'ext.lib';

function func(arg1: PChar; arg2: Longint; arg3: PChar; arg4: PChar; arg5: PChar; arg6: PPChar): Longint; cdecl; external ext;
..
rc := func(Pchar('arg1'), 0, nil, nil, PChar('arg5'), nil);

The function is behind a button click, so it is not executed on startup. When I launch the executable I always get the following error:

'ext.lib is either not designed to run on Windows or it contains an error. Try installing the program again using the original installation media or contact your system administrator or the software vendor for support'.

Now to be sure that the library is OK I created a Visual C++ project calling the same function and that works fine, but I noticed I had to add a couple of additional libraries in order to satisfy the linker.

Do I have to include these libraries as well? If so how? I tried to: add the libraries to the project, use external declarations for each library, add additional linker options, but so far nothing seems to work.

Regards,
Gijsbert


exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Error when trying to use an external C library
« Reply #2 on: June 28, 2013, 06:48:52 pm »
external directive is not designed to link with static libraries. .lib files are static libraries compiled with M$ native compilers. You can link with VC++ because VC++ might already have references to other libraries required to make it run (e.g. M$ C/C++ RTL). A suggested solution is to compile the library as dynamic instead of static (so that everything required is included and isolated in the dll).

 

TinyPortal © 2005-2018