Skip to content

Undefined reference to function while compiling .c and .cpp files. #741

@arteevraina

Description

@arteevraina

After this PR got merged in the main branch. I tried to compile stdlib using new build of fpm. I was still getting the same error

test/hash_functions/test_hash_functions.f90 which is giving me this error :
undefined reference to generate_all_c_hash

This issue is not just limited to .cpp files, but .c files also show the same error while compiling. To test that out, I have created a modified version of with_c example for testing. You can check this out here.

FPM VERSION : I am running the executable fpm version of the current main branch.

Logs for Reproducible Example


(env) arteev@pavilion:~/reproducible-example$ fpm build
c_code.c                               done.
with_c.f90                             done.
libwith_c.a                            done.
main.f90                               done.
with_c                                 failed.
[100%] Compiling...
/usr/bin/ld: build/gfortran_2A42023B310FA28D/with_c/libwith_c.a(src_with_c.f90.o): in function `__with_c_MOD_system_isdir':
/home/arteev/reproducible-example/./src/with_c.f90:22: undefined reference to `my_isdir'
collect2: error: ld returned 1 exit status
<ERROR> Compilation failed for object " with_c "
<ERROR>stopping due to failed compilation
STOP 1



Show Model for Reproducible Example

(env) arteev@pavilion:~/reproducible-example$ fpm build --show-model|sed "s/,/,\n/g" -
 fpm_model_t(package_name="with_c",
 packages=[package_t(name="with_c",
 sources=[srcfile_t(file_name="app/c_code.c",
 exe_name="",
 unit_scope=FPM_SCOPE_APP,
 modules_provided=[],
 parent_modules=[],
 unit_type=FPM_UNIT_CSOURCE,
 modules_used=[],
 include_dependencies=[],
 link_libraries=[],
 digest=-4855192256658658792),
 srcfile_t(file_name="app/main.f90",
 exe_name="with_c",
 unit_scope=FPM_SCOPE_APP,
 modules_provided=[],
 parent_modules=[],
 unit_type=FPM_UNIT_PROGRAM,
 modules_used=["with_c"],
 include_dependencies=[],
 link_libraries=[],
 digest=9186979595472880402),
 srcfile_t(file_name="./src/with_c.f90",
 exe_name="",
 unit_scope=FPM_SCOPE_LIB,
 modules_provided=["with_c"],
 parent_modules=[],
 unit_type=FPM_UNIT_MODULE,
 modules_used=[],
 include_dependencies=[],
 link_libraries=[],
 digest=6240126590444891773)])],
 compiler=(fc="gfortran",
 cc="gcc"),
 archiver=(ar="ar -rs "),
 fortran_compile_flags=" -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single",
 c_compile_flags="",
 cxx_compile_flags="",
 link_flags="",
 build_prefix="build/gfortran",
 link_libraries=[],
 external_modules=[],
 deps=dependency_tree_t(...))

cc: @awvwgk @LKedward @jvdp1 @zoziha

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions