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

Add flags to link main programs with C/C++ main #896

Merged
merged 5 commits into from
May 9, 2023

Conversation

perazz
Copy link
Contributor

@perazz perazz commented Apr 27, 2023

Address #895. I believe this slight change should be enough for now.

Comment on lines 310 to 319
! If the main program is on a C/C++ source, the Intel Fortran compiler requires option
! -nofor-main to avoid "duplicate main" errors.
! https://stackoverflow.com/questions/36221612/p3dfft-compilation-ifort-compiler-error-multiple-definiton-of-main
if (model%compiler%is_intel() .and. any(exe_type==[FPM_TARGET_C_OBJECT,FPM_TARGET_CPP_OBJECT])) then
if (get_os_type()==OS_WINDOWS) then
targets(size(targets))%ptr%compile_flags = '/nofor-main'
else
targets(size(targets))%ptr%compile_flags = '-nofor-main'
end if
end if
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put this in the compiler type to provide us with extra link / compile flags?

Copy link
Contributor Author

@perazz perazz Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep - done. Unfortunately after that location the link between the .exe target and the fact that it comes from a C/C++ source is lost (two separate targets are made: the object and the executable), so, I can't call for the flags from elsewhere, but at least it's better coded.

Sorry for the many more commits - I believe I've hit a compiler bug with strings that kept working on my unit but failed on the CI.

move main flags to `compiler_t`

fix char allocation

debugging prints

default init

use subroutine, not function

no fortran

no empty string

use temporary variable

use associate
@perazz
Copy link
Contributor Author

perazz commented Apr 30, 2023

Please let me know if this is a reasonable solution, so I can go back to working on Intel-MPI on #859

@perazz perazz mentioned this pull request May 3, 2023
9 tasks
@perazz
Copy link
Contributor Author

perazz commented May 6, 2023

Added flags for pgif90 and nvfortran, as suggested in #895

@arteevraina
Copy link
Member

@perazz Looks good to me.

@perazz
Copy link
Contributor Author

perazz commented May 6, 2023

Thank you @arteevraina. Any more comments @egiovan? Otherwise, I think this can be merged.

@perazz perazz changed the title Add -nofor-main flag to Intel linking main programs with C/C++ source Add flags to link main programs with C/C++ main May 6, 2023
Copy link
Member

@henilp105 henilp105 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @perazz , Looks good to me.

@perazz
Copy link
Contributor Author

perazz commented May 9, 2023

If there are no more comments, I will merge later today.

@perazz
Copy link
Contributor Author

perazz commented May 9, 2023

Merging now.

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

Successfully merging this pull request may close these issues.

4 participants