Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Compilation issues. New to F2003/8, JSON #231

Closed
towtruck1 opened this issue Nov 10, 2016 · 13 comments
Closed

Compilation issues. New to F2003/8, JSON #231

towtruck1 opened this issue Nov 10, 2016 · 13 comments

Comments

@towtruck1
Copy link

towtruck1 commented Nov 10, 2016

Hello

I've been doing non-modern FORTRAN for years, but am new to OOF (2003, 2008) and also new to JSON, so your patience is appreciated. I created a simple test program and immediately ran into compilation problems. The trouble is, I don't know if I am doing something wrong, or if there is a bug in the code.

Issue 1:
$ make
gfortran -O2 -I/usr/include -c json_kinds.F90
gfortran -O2 -I/usr/include -c json_parameters.F90
gfortran -O2 -I/usr/include -c json_string_utilities.F90
gfortran -O2 -I/usr/include -c json_value_module.F90
gfortran -O2 -I/usr/include -c json_file_module.F90
gfortran -O2 -I/usr/include -c json_module.F90
gfortran -O2 -I/usr/include -c JSONmp.F90
JSONmp.F90:39:35:

 call json%get_json_core_in_file(jCore)
                               1

Error: ‘get_json_core_in_file’ at (1) is not a member of the ‘json_file’ structure
make: *** [Makefile:63: JSONmp.o] Error 1

I "fixed" this by making a change in json_file_module.F90

added:
procedure :: get_json_core_in_file
after:
procedure :: set_json_core_in_file


Issue 2:
$ make
gfortran -O2 -I/usr/include -c json_kinds.F90
gfortran -O2 -I/usr/include -c json_parameters.F90
gfortran -O2 -I/usr/include -c json_string_utilities.F90
gfortran -O2 -I/usr/include -c json_value_module.F90
gfortran -O2 -I/usr/include -c json_file_module.F90
gfortran -O2 -I/usr/include -c json_module.F90
gfortran -O2 -I/usr/include -c JSONmp.F90
gfortran -O2 -I/usr/include -o JSONmp JSONmp.o json_kinds.o json_parameters.o json_string_utilities.o json_value_module.o json_file_module.o json_module.o
JSONmp.o:JSONmp.F90:(.text+0x428): undefined reference to json_info_' JSONmp.o:JSONmp.F90:(.text+0x428): relocation truncated to fit: R_X86_64_PC32 against undefined symbol json_info_'
JSONmp.o:JSONmp.F90:(.text+0x4cb): undefined reference to json_value_get_by_index_' JSONmp.o:JSONmp.F90:(.text+0x4cb): relocation truncated to fit: R_X86_64_PC32 against undefined symbol json_value_get_by_index_'
JSONmp.o:JSONmp.F90:(.text+0x4ed): undefined reference to json_info_' JSONmp.o:JSONmp.F90:(.text+0x4ed): relocation truncated to fit: R_X86_64_PC32 against undefined symbol json_info_'
collect2: error: ld returned 1 exit status
make: *** [Makefile:54: JSONmp] Error 1

I "fixed" this one by making a change in json_value_module.F90

commented out (line ~24):
!private

My test code (JSONmp.F90, below) compiled fine & gave me the result I expected after I made the changes enumerated above. If anyone would take a few moments to set me straight, I would appreciate it. Thanks!

    program testJSON
	! Program to test the functionality of json-fortran
	!(http://jacobwilliams.github.io/json-fortran/index.html)
	
	! Pull in the json-fortran classes
	use json_kinds
	use json_parameters
	use json_value_module
	use json_file_module	
	use json_module
	
	implicit none

	! declare local variables
	type(json_file)		:: json
	integer				:: i
	character(len=24)	:: filename
	character(len=:), allocatable :: name

	type(json_value), pointer	:: pJval, pJval_c
	type(json_core)				:: jCore
	integer(kind=IK)			:: var_type
	integer(kind=IK)			:: n_children
	
	call json%initialize(compact_reals=.true.)
	
	! open a *.json file.
	write(*,*) 'Enter JSON filename:'
	read(*,*) filename
	call json%load_file(filename=filename)
	
	!print to the console for verification
	call json%print_file()

	! get the json_core and the root json_value for the call to json_info etc.
	call json%get_json_core_in_file(jCore) 
	call json%json_file_get_root(pJval) 
    
	! Try out a few thigs
	call json_info(jCore, pJval, var_type, n_children, name) 
	write(*,*) n_children, 'children found for ', name
	do i=1, n_children
		call json_value_get_by_index(jCore, pJval, i, pJval_c)
		call json_info(jCore, pJval_c, var_type, n_children, name) 
		write(*,*) n_children, 'children found for ', name
	enddo
	
	call json%destroy()
	
    end
@zbeekman
Copy link
Contributor

How are you building? I don't think we distribute a makefile, the supported installation methods I'm aware of are via CMake, or install.sh which requires FoBiS.py (which requires python). Also which gfortran are you using and which OS and which version of JSON-Fortran.

There may be legitimate issues, I'm not doubting you, but I would like to gather more info and see what happens if you try installing via a supported means. Oh, btw if you're on Mac OS X you can get it through the Homebrew package manager and it may be in a Linux package manager, not sure.

@towtruck1
Copy link
Author

towtruck1 commented Nov 10, 2016

Thanks for the response!
I am compiling/linking on cygwin, so that would be minGW. My memory is a bit hazy, because that was all new to me too, but I believe I had to install gfortran separately. I am using a Makefile I adapted for this myself. Originally, I created the json-fortrtan library separately and linked to that, but to rule out the possibility that I wasn't referencing the library correctly, I built it all together (turns out it was all the same). Cygwin, and therefore minGW with gfortran, have all been installed in the last week or so from here:
http://mingw-w64.org/doku.php/download/cygwin

The json-fortran-master.zip file I downloaded from Github shows Date Modified of 10/28/2016.

Enclosed is my Makefile. Thanks again for your response.

#$preamble
# A simple hand-made makefile for a package including applications
# built from Fortran 90 sources, taking into account the usual
# dependency cases.

# This makefile works with the GNU make command, the one find on
# GNU/Linux systems and often called gmake on non-GNU systems, if you
# are using an old style make command, please see the file
# Makefile_oldstyle provided with the package.

# The compiler
FC = gfortran
# flags for debugging or for maximum performance, comment as necessary
FCFLAGS = -g -fbounds-check
FCFLAGS = -O2
# flags forall (e.g. look for system .mod files, required in gfortran)
FCFLAGS += -I/usr/include

# For right now, build everything here (don't use library)
LIBS = 
MODS = 


# List of executables to be built within the package
PROGRAMS = JSONmp

# "make" builds all
all: $(PROGRAMS)


json_parameters.o: json_kinds.o
json_string_utilities.o: json_parameters.o
json_value_module.o: json_kinds.o json_parameters.o json_string_utilities.o
JSONmp.o: json_value_module.o json_file_module.o json_module.o

JSONmp: json_kinds.o json_parameters.o json_string_utilities.o json_value_module.o json_file_module.o json_module.o


# General rule for building prog from prog.o; $^ (GNU extension) is
# used in order to list additional object files on which the
# executable depends
%: %.o
    $(FC) $(FCFLAGS) -o $@ $^ $(LDFLAGS)  $(LIBS) $(MODS) 

# General rules for building prog.o from prog.f90 or prog.F90; $< is
# used in order to list only the first prerequisite (the source file)
# and not the additional prerequisites such as module or include files
%.o: %.f90
    $(FC) $(FCFLAGS) -c $<  $(LIBS) $(MODS) 

%.o: %.F90
    $(FC) $(FCFLAGS) -c $<  $(LIBS) $(MODS) 

# Utility targets

clean:
    rm -f *.o *.mod *.MOD

@zbeekman
Copy link
Contributor

Can you give me the output of gfortran --version

Also have you tried one of the official releases?

@towtruck1
Copy link
Author

$ gfortran --version
GNU Fortran (GCC) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.

No, I wasn't aware of an official release. I'll check into it.

Thanks!

@towtruck1
Copy link
Author

Thanks again. I just downloaded json-fortran-5.1.0. So far I have the same 1st issue:

$ make
gfortran -O2 -I/usr/include -c JSONmp.F90
JSONmp.F90:36:32:

  call json%get_json_core_in_file(jCore)
                                1
Error: ‘get_json_core_in_file’ at (1) is not a member of the ‘json_file’ structure
make: *** [Makefile:52: JSONmp.o] Error 1

@jacobwilliams
Copy link
Owner

I don't use Make, so I can't answer any question about it.

However, your code has several issues. The json-fortran code doesn't need any modifications to do what you want. You can't call the private routines, you have to use the public ones in the json_core and json_file classes. The corrected version is:

program testJSON

! You only have to use this (note that we are renaming the json_IK variable)
use json_module, IK=>json_IK

implicit none

! declare local variables
type(json_file)        :: json
integer                :: i
character(len=24)      :: filename
character(len=:), allocatable :: name

type(json_value), pointer   :: pJval, pJval_c
type(json_core)             :: jCore
integer(kind=IK)            :: var_type
integer(kind=IK)            :: n_children

call json%initialize(compact_reals=.true.)

! open a *.json file.
write(*,*) 'Enter JSON filename:'
read(*,*) filename
call json%load_file(filename=filename)

!print to the console for verification
call json%print_file()

! get the json_core and the root json_value for the call to json_info etc.
call json%get_core(jCore)
call json%get(pJval)

! Try out a few thigs
call jCore%info(pJval, var_type, n_children, name)
write(*,*) n_children, 'children found for ', name
do i=1, n_children
    call jCore%get_child(pJval, i, pJval_c)
    call jCore%info(pJval_c, var_type, n_children, name)
    write(*,*) n_children, 'children found for ', name
enddo

call json%destroy()

end program testJSON

For example, get_child is the generic public name that points to several private routines in the class. So, you don't call json_value_get_by_index(jCore, pJval, i, pJval_c), you call jCore%get_child(pJval, i, pJval_c).

@towtruck1
Copy link
Author

Thank you Jacob
This is the answer I was expecting (in concept, otherwise I wouldn't have asked).

I think my real issue is with understanding how FORD presents the documentation, as I still don't really know where to look for the actual API (public functions/interfaces). I found (for example) where 'info' was documented, but now only because I was looking for it. The public interfaces seem to be buried on the same long page that also has all the private functions etc, so I feel like I am looking for a needle in a haystack when I don't even know what the needle looks like. I guess I show my real ignorance in saying that but I don't mind. Is there anyplace that has just the public interfaces?

Thanks again!

@zbeekman
Copy link
Contributor

We at least had a discussion about including only public functions for the release documentation (and I'm traveling today and have been corresponding from my phone--why I didn't dig into your code and come to the realization Jacob did) but I don't remember what we decided. Are you looking at the online documentation or locally built documentation?

@zbeekman
Copy link
Contributor

Perhaps the following changes should be made:

  1. We only generate documentation for public and protected entities for releases.
  2. The documentation lands on the latest release's documentation by default (with a link to development documentation for master)
  3. Test documentation is in the development documentation but not the release documentation

@towtruck1 do you think that would be a step in the right direction for clarifying end user API?
FYI releases can be found at https://github.com/jacobwilliams/json-fortran/releases

@jacobwilliams: thoughts?

@towtruck1
Copy link
Author

towtruck1 commented Nov 11, 2016

Thanks!
I've been looking at the online documentation. I assumed it would be substantially the same as any I built. And, yes, even for for people who are not low on the learning curve as I am, I think it would be a great step in the right direction for clarifying end-user API. Thanks for considering it!

@jacobwilliams
Copy link
Owner

@zbeekman I agree with all this!

@zbeekman
Copy link
Contributor

@towtruck1 if you can build the documentation locally, then you can delete the line with private on it in the meta data section of the FORD project file (json-fortran.md) shown below:

display: public
         protected
         private

deleting that line (private) and rebuilding the documentation will only show publicly visible documentation.

Should we close this issue and open a new one to track the documentation changes.

@towtruck1
Copy link
Author

Thanks. I'll give it a go. And I'll close this issue & let you open a new one to track the documentation changes.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants