Sign in Join

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

Mailing lists / fpc-pascal / 2013-09

Bug in $linklib?

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Xiangrong Fang

Hi All,

I use $linklib to link my fpc program with a C++ so file. I found that the $linklib directive does NOT conform with ld specification. This is what I did and found:

PURPOSE

I want to link to a C library that does NOT start with "lib" prefix. The library's name is thostmduserapi.so

PROCEDURE

I tried to use {$linklib thostmduserapi}, fpc complains:

ld: cannot find -lthostmduserapi

If I rename thostmduserapi.so to libthostmduserapi.so, the problem is solved, however this is exactly what I *don't* want -- add lib prefix to so file.

After checking the ld man page, I learned that:

If namespec is of the form :filename, ld will search the library path for a file called filename, otherwise it will search the library path for a file called libnamespec.a.

So I tried: {$linklib :thostmduserapi.so}. This time, fpc complains:

ld: cannot find thostmduserapi

I added -st to fpc, and get the following in the generated link.res file:

INPUT(
-l:thostmduserapi
-lstdc++
-lgcc_s
)

I manually changed the script to -l:thostmduserapi.so, and it linked without problem!

I think the process of generating link script is buggy, because it does not conform with ld specification.

Regards,
Xiangrong

Jonas Maebe
to Xiangrong Fang
Xiangrong Fang wrote
I use $linklib to link my fpc program with a C++ so file. I found that the $linklib directive does NOT conform with ld specification.

Directives conform with the fpc specifications. Not all platforms use GNU ld, and additionally ":" is a valid character in file names on Unix platforms. Either rename the library so it conforms to the standard platform conventions or us fpc's -k parameter to pass command line options directly to the linker.

Jonas