English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 27 October 2021, 00:01   #1
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 962
How can I use third party libraries in my project?

I am trying to use a regex library in my project. I found this regex library from aminet but cannot understand how to include this in my project.

I compile my executable using a make file. I have placed regex.library in my project directory. I then edited my makefile with the -L. and -l flags as follows;

Code:
LIBS = -lamiga -lauto -L. -lregex
However when I try to compile I get an error message saying "Cannot open -lregex. No such file or directory."

I have tried -lregex.library or moving the regex.libraty to the System:Libs but to no avail.

Anyone knows how I can include a third party library to my project?
Sim085 is offline  
Old 27 October 2021, 05:41   #2
Steady
Registered User
 
Join Date: May 2021
Location: Melbourne, Australia
Posts: 40
What the compiler library is looking for is a linker library, which is different from an Amiga library, which this is.

To access that library, ensure that all that library's header and proto files are accessible, include them in your source code and then use OpenLibrary() from AmigaOS to open that library and start accessing. Don't forget to CloseLibrary() after you are finished.

-lauto won't automatically open that library for you because it doesn't know that 3rd party library.
Steady is offline  
Old 27 October 2021, 08:06   #3
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 962
So I have now also placed regex.lib in my source directory. This means that in my source directory I now have regex.library, regex.lib and regex.h. I use the flags -L. and -lregex. The error message has now changed to "Fatal error 11. regex.lib: File format not recognized". Do I need to recompile the library using my compiler for it to work?



Quote:
Originally Posted by Steady View Post
What the compiler library is looking for is a linker library, which is different from an Amiga library, which this is.

To access that library, ensure that all that library's header and proto files are accessible

Last edited by Sim085; 27 October 2021 at 10:27.
Sim085 is offline  
Old 27 October 2021, 10:28   #4
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by Sim085 View Post
"Fatal error 11. regex.lib: File format not recognized".
Looks like this is a linker library in Aztec-C "lb" format. Only the Aztec linker might be able to use it.
(Is there a description of that format somewhere?)

Quote:
Do I need to recompile the library using my compiler for it to work?
This is one solution. Although there may be Aztec-C specific hacks in the source. And the C source is really old, from before even ANSI-C90 existed. So you can expect lots of errors and warnings with modern compilers.

Unfortunately the author didn't provide an FD file for his shared library. Otherwise the normal procedure to use third party libraries would be to simply regenerate the linker library, proto- and inline headers for it with fd2pragma.

You could also try to create an FD file yourself from the information provided in interface.asm.
phx is offline  
Old 27 October 2021, 11:45   #5
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 962
I can see some other distributions of regex on aminet that do have an fd file.

Are there any guides how I can regenerate the linker library from this?

Quote:
Originally Posted by phx View Post
Unfortunately the author didn't provide an FD file for his shared library. Otherwise the normal procedure to use third party libraries would be to simply regenerate the linker library, proto- and inline headers for it with fd2pragma.
Sim085 is offline  
Old 27 October 2021, 12:26   #6
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Linker library with stub functions:
Code:
fd2pragma special 12 to vlibos3: hunkname CODE regex.fd
Proto header file:
Code:
fd2pragma special 38 to vincludeos3:proto regex.fd
Header file with vbcc assembler inline calls:
Code:
fd2pragma special 70 voidbase to vincludeos3:inline regex.fd clib path_to/clib/regex_protos.h
Or use the portable fd2pragma-syntax when running it under Unix/MacOS/Windows: -s to special, -t for to, -c for clib,m -i for the FD-file, etc.
phx is offline  
Old 28 October 2021, 11:48   #7
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 962
I am having problems with the last step.

I have modified as follows;

Code:
fd2pragma special 70 voidbase to vincludeos3:inline regexp.fd clib vincludeos3:proto/RegExp.h
(i.e. - used the file generated from previous step).

However I get the following output:
Code:
SourceFile: regexp.fd
ResultFile: vincludeos3:inline/RegExp_protos.h
Error 27 : No prototupes file (CLIB parameter) was specified.
What is the clib directory referring to? I went to vbcc directory where the proto was generated in previous step.


Quote:
Originally Posted by phx View Post
Code:
fd2pragma special 70 voidbase to vincludeos3:inline regex.fd clib path_to/clib/regex_protos.h

Last edited by Sim085; 29 October 2021 at 11:40.
Sim085 is offline  
Old 29 October 2021, 11:02   #8
kamelito
Zone Friend
 
kamelito's Avatar
 
Join Date: May 2006
Location: France
Posts: 1,801
Quote:
Originally Posted by phx View Post
Looks like this is a linker library in Aztec-C "lb" format. Only the Aztec linker might be able to use it.
(Is there a description of that format somewhere?)

This is one solution. Although there may be Aztec-C specific hacks in the source. And the C source is really old, from before even ANSI-C90 existed. So you can expect lots of errors and warnings with modern compilers.

Unfortunately the author didn't provide an FD file for his shared library. Otherwise the normal procedure to use third party libraries would be to simply regenerate the linker library, proto- and inline headers for it with fd2pragma.

You could also try to create an FD file yourself from the information provided in interface.asm.
There’s a site about all Aztec C versions including informations at http://www.aztecmuseum.ca/
kamelito is offline  
Old 29 October 2021, 12:09   #9
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 962
Just to clarify that I have moved to this distribution which comes with a .fd file.
https://aminet.net/package/util/libs/RegExpLib

From what I understand the first command creates the linker library from the fd file. The second command is creating the header file (under the proto directory of vbcc), this is what I would include in my source files.

However I do not understand what the third command is doing.

When I open the header file generated I can see there is the following entry but I cannot identify any clib directory under my vbcc installation.

Code:
#if !defined(CLIB_REGEXP_PROTOS_H) && !defined(__GNUC__)
#include <clib/RegExp_protos.h>
#endif
I can also see the following;

Code:
#elif defined(__VBCC__)
#include <inline/RegExp_protos.h>
I assume is the rule that applies for me given I am using vbcc. However I cannot get this file without the third command
Sim085 is offline  
Old 29 October 2021, 18:50   #10
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by kamelito View Post
There’s a site about all Aztec C versions including informations at http://www.aztecmuseum.ca/
Nice site, although I was unable to find any information about the format of the Aztec-C lb library-tool.
phx is offline  
Old 29 October 2021, 19:09   #11
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by Sim085 View Post
From what I understand the first command creates the linker library from the fd file. The second command is creating the header file (under the proto directory of vbcc), this is what I would include in my source files.
Correct.

Quote:
However I do not understand what the third command is doing.
It generates assembler inlines to call the library functions directly, without going over the stub routines from the linker library. vbcc generally puts these inline-headers into the
inline
directory with the name
libname_protos.h
.

It is automatically included and used as soon as you include
<proto/libname.h>
. If you want to use the stubs, you would include
<clib/libname_protos.h>
instead.

Quote:
When I open the header file generated I can see there is the following entry but I cannot identify any clib directory under my vbcc installation.
The clib directory is in the official NDK. All third party libraries are expected to provide their function proto types in a clib header file and follow the general naming of
clib/libname_protos.h
.

This doesn't seem to be the case with the RegExp library you found - which is also somewhat old...

Looking into the RegExpLib archive I guess that
regexp.h
is meant as proto/clib header file - it even includes pragmas for SAS/C inline calls.

You can try copying it into your clib directory and rename it to
RegExp_protos.h
. Then use it with the clib option from the "special 70" fd2pragma call. fd2pragma needs these proto types to generate valid inline functions with matching types.

EDIT: If you don't care about optimized library calls, just delete the
#include <inline/RegExp_protos.h>
from your proto-header and you're done.

Last edited by phx; 29 October 2021 at 19:15.
phx is offline  
Old 08 November 2021, 18:25   #12
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 962
Hi phx, I did manage to get it to work by moving the header to the clib directory and then continued the steps from there.

Wanted to thank you for all your help.
Sim085 is offline  
Old 08 November 2021, 22:20   #13
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
phx is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
M68K and libraries rcman Coders. Asm / Hardware 3 05 February 2020 21:03
New / updated XPK libraries andy2004 support.Apps 0 16 September 2019 16:55
Libraries Syntrax support.Other 6 31 March 2019 15:59
Missing Libraries manicx support.Apps 3 04 June 2003 09:02

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:42.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.12238 seconds with 13 queries