Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Error was shown when build command was employed #30

Open
VOLCANIC-9 opened this issue Feb 13, 2021 · 6 comments
Open

Error was shown when build command was employed #30

VOLCANIC-9 opened this issue Feb 13, 2021 · 6 comments

Comments

@VOLCANIC-9
Copy link

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?

@ylikx
Copy link
Owner

ylikx commented Feb 14, 2021

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?

@VOLCANIC-9
Copy link
Author

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?

@ylikx
Copy link
Owner

ylikx commented Feb 15, 2021

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

@VOLCANIC-9
Copy link
Author

VOLCANIC-9 commented Feb 19, 2021

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.

@ylikx
Copy link
Owner

ylikx commented Feb 19, 2021

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

@VOLCANIC-9
Copy link
Author

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.

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

No branches or pull requests

2 participants