forpy icon indicating copy to clipboard operation
forpy copied to clipboard

Error was shown when build command was employed

Open VOLCANIC-9 opened this issue 3 years ago • 6 comments

I use the last version of Geany IDE with sync to the last version of Anaconda. I build my code in Windows 7 64-bit. When I typed the build command:

# Python 3.8 and higher
gfortran -c forpy_mod.F90
gfortran intro_to_forpy.F90 forpy_mod.o `python3-config --ldflags --embed`

, it showed errors:

gfortran: error: `python3-config: No such file or directory
gfortran: error: unrecognized command line option '--ldflags'
gfortran: error: unrecognized command line option '--embed`'
Compilation failed.

I want to know how this error appeared and how can I solve it?

VOLCANIC-9 avatar Feb 13 '21 22:02 VOLCANIC-9

Hi, I have not tried this kind of setup on Windows and I'm not sure if python3-config is available from some anaconda package. However it's possible to build on Windows without python3-config. See https://github.com/ylikx/forpy/wiki/Forpy-on-Windows for an example with Miniconda3/MinGW/Codeblocks. The trick is to link with PythonXY.dll (depending on version e. g. Python37.dll). (On Linux the equivalent would be achieved with the -lpython37 flag in the linking step). What is your setup regarding gfortran?

ylikx avatar Feb 14 '21 22:02 ylikx

I install also one Python compiler alone, but the code still shows errors. "What is your setup regarding gfortran?" I didn't notice but I install the MinGW package for Fortran. If I understand what you mean: I need a linker program that links the python compiler (e.g. Anaconda python compiler) to my code. If it is correct can you recommend a sample of these programs kind?

VOLCANIC-9 avatar Feb 15 '21 17:02 VOLCANIC-9

I checked the Codeblocks example again and the command used for linking with the Python runtime library was:

x86_64-w64-mingw32-gfortran.exe -LC:\Users\username\Anaconda3 -o main.exe forpy_mod.o main.o   -lpython37

(adjust paths and filenames according to your project)

I also had to set the PYTHONHOME environment variable to run the example:

set PYTHONPATH=C:\Users\username\Anaconda3

ylikx avatar Feb 15 '21 21:02 ylikx

If I understand the building program logic of your project:

  1. Compile the "forpy_mod.f90" to create an object file -> "forpy_mod.o"
  2. Compile the "main.f90" to create an object file -> "main.o"
  3. Link "forpy_mod.o", "main.o", and "python3.dll" with a linker or any manner
  4. create the executable file -> "main.exe" Now, the problem is: when I compile "forpy_mod.f90" to create "forpy_mod.o", the code shows many errors. Consequently, the object file is not created. If I made a mistake in the above description, please mention it.

VOLCANIC-9 avatar Feb 19 '21 12:02 VOLCANIC-9

Yes, that's basically correct. main.f90 is just the filename of my code example.

forpy_mod should have the extension .F90, since it needs to be preprocessed: use the filename forpy_mod.F90 instead of forpy_mod.f90 - maybe this was the cause of the error messages. Alternatively you could use the option -cpp The command to build forpy_mod.o should therefore be

gfortran -c forpy_mod.F90

or

gfortran -c -cpp forpy_mod.f90

ylikx avatar Feb 19 '21 21:02 ylikx

Thanks, for your attention. Your code works properly. However, I want to keep this issue open until I provide a complete solution for Windows and any IDE. I hope you keep it open too.

VOLCANIC-9 avatar Feb 24 '21 09:02 VOLCANIC-9