Skip to content

Commit 7515a01

Browse files
authored
Update README.md
1 parent a9cc697 commit 7515a01

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,37 @@ Prior to ``make install ``, though optional, it is good practice to test the bui
4343
### Install
4444

4545
``> [sudo] [FC=... FFLAGS="..." PREFIX="..."] make install`` **(sudo access required to install to system area)**
46+
47+
## Usage
48+
49+
This package provides a module file (**``<prefix>/include/strings.mod``**) and both a shared object library (**``<prefix>/lib/libfstrings.so``**) and a static library (**``<prefix>/lib/libfstrings.a``**). To use this ``fortran-strings`` in your Fortran program, you must use the ``USE`` statement in your main program or procedure source and during compile, you must specify the library of your choice to the compiler/linker.
50+
51+
Example code:
52+
```fortran
53+
program test
54+
use strings
55+
implicit none
56+
57+
character(len=:), allocatable :: mystring
58+
integer :: icount
59+
60+
mystring="Hello World! Hello from Fortran!"
61+
icount=str_count(mystring,"Hello") ! Return a count of "Hello" in mystring
62+
write(6,*)"icount = ",icount
63+
64+
end program test
65+
```
66+
67+
Example compile and link to ***static*** library using gfortran:
68+
```bash
69+
gfortran -I<prefix>/include -o test.x test.f90 <prefix>/lib/libfstrings.a
70+
```
71+
72+
Note that this does not make the executable 100% static.
73+
74+
Example compile and link to ***shared object*** library using gfortran:
75+
```bash
76+
gfortran -I<prefix>/include -o test.x test.f90 -L<prefix>/lib -lfstrings
77+
```
78+
79+
Note that when compiling and linking to shared object libraries, the library path must be specified in the appropriate environment variable prior to invocation (Linux: ``LD_LIBRARY_PATH``; macOS: ``DYLD_LIBRARY_PATH``).

0 commit comments

Comments
 (0)