Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-05

Undefined symbols. Help!

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Anthony Walter

Can someone point me in the right direction towards solving this problem?

I built a static libraries on Linux based on some open source c and h files. I can compile things fine with gcc/mingw-265 and use ar to turn the object files into a static lib (libtess.a). The problem is when I try to compile on Windows with the static lib I get the linking errors below when I try to compile and exe which uses the functions I'm importing:

Error: Undefined symbol: _malloc
Error: Undefined symbol: _free
Error: Undefined symbol: __assert
Error: Undefined symbol: __setjmp3
Error: Undefined symbol: _longjmp
Error: Undefined symbol: _realloc
Fatal: There were 6 errors compiling module, stopping

In one of my packages I am doing this:

{$linklib tess} // libtess.a compiled using i686-mingw-w64-gcc on Linux

On Linux I ran an nm command in the mingw-w64 folder and found those functions in libmsvcrt.a and libmsvcr100.a ... so I copied those files to my windows box and tried linking with each one (separately {$linklib msvcrt} for example) as well, but I still get the same linking errors. I also tried linking in ...

{$linklib user32}
{$linklib kernel32}
{$linklib msvcr100}
{$linklib mingw32}
{$linklib tess}

I'd really appreciate it if anyone could help me better understand how to work with static libraries compiled on Linux and linked on Windows.

Thanks.

Anthony Walter
to leledumbo

Okay, had tried ...

{$linklib msvcrt} // libmsvcrt.a copied from Linux /usr/i686-mingw-w64/lib
{$linklib tess} // my static lib

Then I installed dependency walker (per your advice) and inspected msvcrt.dll. That dll seems to have the missing functions but with the names a bit different in places (it has a malloc, but no _malloc). I swapped the linklib below reversing the order:

{$linklib tess}
{$linklib msvcrt}

And tried to recompile a program. Now the only undefined symbols are:

Error: Undefined symbol: __assert
Error: Undefined symbol: _longjmp
Fatal: There were 2 errors compiling module, stopping

Looking at the msvcrt.dll function list in dependency walker is see:

_assert
longjmp

So FPC is not picking up these functions. What should I try next to get those two functions linking?

Anthony Walter
to Anthony Walter

I got it. I found all the required static libraries by going searching through nm *.a on Linux and looking for which library had the missing functions, then I linked to that lib which gave me a whole new set of missing functions and I repeated the process until nothing was missing. Also, everything has to be in the right order as well.

{$linklib mingwex}
{$linklib mingw32}
{$linklib msvcrt}
{$linklib kernel32}
{$linklib user32}
{$linklib crtdll}