View Issue Details

IDProjectCategoryView StatusLast Update
0038369FPCDocumentationpublic2021-01-24 21:48
ReporterTrevor Roydhouse Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformAppleOSmacOS 
Fixed in Version3.3.1 
Summary0038369: 12.3 Using a library in a pascal program (code fix)
Descriptionhttps://www.freepascal.org/docs-html/current/prog/progse56.html

Listing: progex/psubs.pp is missing {$linklib libsubs} at the start without which compilation fails with:

Undefined symbols for architecture x86_64:
  "_SubStr", referenced from:
      _PASCALMAIN in dynlibtest.o
ld: symbol(s) not found for architecture x86_64
An error occurred while linking ... etc.

Also, I query the inclusion of 'subs' in the line:

function SubStr(const CString: PChar; FromPos, ToPos: longint): PChar; cdecl; external ’subs’;

Including it or omitting it makes no difference in my tests, but maybe I'm missing the reason for its inclusion.
Steps To ReproduceTry compiling the code "as is" with the previous page library.
TagsNo tags attached.
Fixed in Revision1796
FPCOldBugId
FPCTarget3.2.2
Attached Files

Activities

Trevor Roydhouse

2021-01-18 08:38

reporter   ~0128395

I just noticed that in Listing: progex/plsubs.pp (which I haven't compiled) there is a constant and ifdefs for the library name for various OS to take account of different OS library naming suffixes, but then the subsequent code does not use them, instead hardcoding "lib:=LoadLibrary(’libsubs.so’);".

Trevor Roydhouse

2021-01-18 08:45

reporter   ~0128396

Ok, I reached the final line of the page and found the note "1 If you omit the library name in the external modifier, then you can still tell the compiler to link to that library using the {$Linklib} directive." However, omitting the directive and including the library filename as in the example still causes a link failure.

Michael Van Canneyt

2021-01-24 19:18

administrator   ~0128568

The external 'subs' tells the compiler the function is in the 'subs' library.
Normally, this should be enough (it is on windows and linux). Apparently on MacOS it is not.

I added this to the text and gave a mac-os specific example as well.

Trevor Roydhouse

2021-01-24 21:48

reporter   ~0128575

Thanks!

Issue History

Date Modified Username Field Change
2021-01-18 08:30 Trevor Roydhouse New Issue
2021-01-18 08:30 Trevor Roydhouse Status new => assigned
2021-01-18 08:30 Trevor Roydhouse Assigned To => Michael Van Canneyt
2021-01-18 08:38 Trevor Roydhouse Note Added: 0128395
2021-01-18 08:45 Trevor Roydhouse Note Added: 0128396
2021-01-24 19:18 Michael Van Canneyt Status assigned => resolved
2021-01-24 19:18 Michael Van Canneyt Resolution open => fixed
2021-01-24 19:18 Michael Van Canneyt Fixed in Version => 3.3.1
2021-01-24 19:18 Michael Van Canneyt Fixed in Revision => 1796
2021-01-24 19:18 Michael Van Canneyt FPCTarget => 3.2.2
2021-01-24 19:18 Michael Van Canneyt Note Added: 0128568
2021-01-24 21:48 Trevor Roydhouse Status resolved => closed
2021-01-24 21:48 Trevor Roydhouse Note Added: 0128575