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

Cannot link C main #643

Closed
awvwgk opened this issue Jan 3, 2022 · 4 comments · Fixed by #646
Closed

Cannot link C main #643

awvwgk opened this issue Jan 3, 2022 · 4 comments · Fixed by #646
Labels
bug Something isn't working

Comments

@awvwgk
Copy link
Member

awvwgk commented Jan 3, 2022

I'm currently trying to (ab)use fpm to compile a C project. It is not a C package manager, but it certainly could become one.

Using a project with the following layout:

fpm.toml
app/main.c

fpm.toml:

name = "test"
[[executable]]
name = "test"
main = "main.c"

app/main.c:

int
main (void) {
  return 0;
}

Will fail to link the C executable with

❯ fpm build
 + mkdir -p build/gfortran_2A42023B310FA28D/test
 + gcc -c app/main.c  -I./include -o build/gfortran_2A42023B310FA28D/test/app_main.c.o
❯ fpm run
<INFO> No executables to run
STOP 0

I think the source scanning must find a program statement in the source-file declared as main in the manifest. Instead, it would be preferable if fpm just trust the user input and assumes that the provided main is providing the necessary entry point.


Tested with fpm 0.5.0

@awvwgk awvwgk added the bug Something isn't working label Jan 3, 2022
@arjenmarkus
Copy link
Member

arjenmarkus commented Jan 3, 2022 via email

@awvwgk
Copy link
Member Author

awvwgk commented Jan 3, 2022

Fpm won't scan C source code for Fortran keywords, therefore it is not able to detect the program statement in the block comment.

@arjenmarkus
Copy link
Member

arjenmarkus commented Jan 3, 2022 via email

@awvwgk
Copy link
Member Author

awvwgk commented Jan 3, 2022

The issue originates in fpm_sources.f90 the branch for Fortran source code

if (str_ends_with(lower(source_file_path), fortran_suffixes)) then

can add an executable by setting the exe_name if a program unit was found

fpm/src/fpm_sources.f90

Lines 34 to 36 in d99ad59

if (source%unit_type == FPM_UNIT_PROGRAM) then
source%exe_name = basename(source_file_path,suffix=.false.)
end if

the else branch for C source and headers is missing this capability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants