Fix LD_LIBRARY_PATH handling for shared libraries during fpm test#1259
Fix LD_LIBRARY_PATH handling for shared libraries during fpm test#1259ZainabTravadi wants to merge 2 commits intofortran-lang:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Ensures fpm test can locate shared libraries by including target output directories in the paths gathered by get_library_dirs() (so LD_LIBRARY_PATH includes the .so directory during test execution).
Changes:
- Initializes
shared_lib_dirsas empty and adds clarifying comments. - Filters considered targets in
get_library_dirs()and addstarget%output_dirwhile deduplicating.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ! Only consider shared and archive library targets | ||
| if (all(target%target_type /= [FPM_TARGET_SHARED,FPM_TARGET_ARCHIVE])) cycle |
There was a problem hiding this comment.
The PR description focuses on fixing runtime discovery for shared libraries, but this change also includes FPM_TARGET_ARCHIVE. Static archives don’t affect LD_LIBRARY_PATH, so either (a) restrict the condition to FPM_TARGET_SHARED only, or (b) update the PR description to explicitly state why archive targets should be included here.
| ! Always include the output_dir for shared libraries | ||
| ! Avoid duplicates |
There was a problem hiding this comment.
These comments are misleading with the current logic: the code path also applies to FPM_TARGET_ARCHIVE due to the filter above. Please adjust the wording to match the implementation (or adjust the implementation to match the comment).
| do i = 1, size(targets) | ||
| associate(target => targets(i)%ptr) | ||
| ! Only consider shared and archive library targets | ||
| if (all(target%target_type /= [FPM_TARGET_SHARED,FPM_TARGET_ARCHIVE])) cycle |
There was a problem hiding this comment.
Using all(target%target_type /= [ ... ]) on a scalar-to-array comparison is correct but non-obvious to many readers. Consider rewriting this as a clearer membership test (e.g., negate an any(target%target_type == [...])) to reduce the chance of misinterpretation during future maintenance.
| if (all(target%target_type /= [FPM_TARGET_SHARED,FPM_TARGET_ARCHIVE])) cycle | |
| if (.not. any(target%target_type == [FPM_TARGET_SHARED,FPM_TARGET_ARCHIVE])) cycle |
|
I updated the implementation to only consider |
When running
fpm testfor projects using shared libraries,the compiled
.sofile may not be found because the directorycontaining the library is not included in
LD_LIBRARY_PATH.This change ensures that shared library output directories
(
target%output_dir) are included when collecting librarypaths via
get_library_dirs().As a result, test executables can locate shared libraries
without requiring users to manually configure
LD_LIBRARY_PATH.Validation:
type="shared".sowithout manually setting
LD_LIBRARY_PATH