@@ -368,20 +368,24 @@ std::string CompileOtherLanguage(std::string path, DriverOptions &driver) {
368
368
return {};
369
369
}
370
370
371
- void Link (std::vector<std::string> &relocatables, DriverOptions &driver) {
371
+ void Link (std::vector<std::string> &liblist, std::vector<std::string> &objects,
372
+ DriverOptions &driver) {
372
373
if (!ParentProcess ()) {
373
374
std::vector<char *> argv;
374
375
for (size_t j{0 }; j < driver.F18_FCArgs .size (); ++j) {
375
376
argv.push_back (driver.F18_FCArgs [j].data ());
376
377
}
377
- for (auto &relo : relocatables ) {
378
- argv.push_back (relo .data ());
378
+ for (auto &obj : objects ) {
379
+ argv.push_back (obj .data ());
379
380
}
380
381
if (!driver.outputPath .empty ()) {
381
382
char dashO[3 ] = " -o" ;
382
383
argv.push_back (dashO);
383
384
argv.push_back (driver.outputPath .data ());
384
385
}
386
+ for (auto &lib : liblist) {
387
+ argv.push_back (lib.data ());
388
+ }
385
389
Exec (argv, driver.verbose );
386
390
}
387
391
}
@@ -396,6 +400,7 @@ int main(int argc, char *const argv[]) {
396
400
bool isPGF90{driver.F18_FCArgs .back ().rfind (" pgf90" ) != std::string::npos};
397
401
398
402
std::list<std::string> args{argList (argc, argv)};
403
+ std::vector<std::string> objlist, liblist;
399
404
std::string prefix{args.front ()};
400
405
args.pop_front ();
401
406
prefix += " : " ;
@@ -412,32 +417,37 @@ int main(int argc, char *const argv[]) {
412
417
413
418
Fortran::common::IntrinsicTypeDefaultKinds defaultKinds;
414
419
415
- std::vector<std::string> fortranSources, otherSources, relocatables ;
420
+ std::vector<std::string> fortranSources, otherSources;
416
421
bool anyFiles{false };
417
422
418
423
while (!args.empty ()) {
419
424
std::string arg{std::move (args.front ())};
425
+ auto dot{arg.rfind (" ." )};
426
+ std::string suffix{arg.substr (dot + 1 )};
427
+ std::string prefix{arg.substr (0 , 2 )};
420
428
args.pop_front ();
421
429
if (arg.empty ()) {
422
430
} else if (arg.at (0 ) != ' -' ) {
423
431
anyFiles = true ;
424
- auto dot{arg.rfind (" ." )};
425
432
if (dot == std::string::npos) {
426
433
driver.F18_FCArgs .push_back (arg);
427
434
} else {
428
- std::string suffix{arg.substr (dot + 1 )};
429
435
if (suffix == " f" || suffix == " F" || suffix == " ff" ||
430
436
suffix == " f90" || suffix == " F90" || suffix == " ff90" ||
431
437
suffix == " f95" || suffix == " F95" || suffix == " ff95" ||
432
438
suffix == " cuf" || suffix == " CUF" || suffix == " f18" ||
433
439
suffix == " F18" || suffix == " ff18" ) {
434
440
fortranSources.push_back (arg);
435
- } else if (suffix == " o" || suffix == " a" ) {
436
- relocatables.push_back (arg);
441
+ } else if (suffix == " o" || suffix == " so" ) {
442
+ objlist.push_back (arg);
443
+ } else if (suffix == " a" ) {
444
+ liblist.push_back (arg);
437
445
} else {
438
446
otherSources.push_back (arg);
439
447
}
440
448
}
449
+ } else if (prefix == " -l" || suffix == " a" ) {
450
+ liblist.push_back (arg);
441
451
} else if (arg == " -" ) {
442
452
fortranSources.push_back (" -" );
443
453
} else if (arg == " --" ) {
@@ -679,17 +689,17 @@ int main(int argc, char *const argv[]) {
679
689
for (const auto &path : fortranSources) {
680
690
std::string relo{CompileFortran (path, options, driver, defaultKinds)};
681
691
if (!driver.compileOnly && !relo.empty ()) {
682
- relocatables .push_back (relo);
692
+ objlist .push_back (relo);
683
693
}
684
694
}
685
695
for (const auto &path : otherSources) {
686
696
std::string relo{CompileOtherLanguage (path, driver)};
687
697
if (!driver.compileOnly && !relo.empty ()) {
688
- relocatables .push_back (relo);
698
+ objlist .push_back (relo);
689
699
}
690
700
}
691
- if (!relocatables .empty ()) {
692
- Link (relocatables , driver);
701
+ if (!objlist .empty ()) {
702
+ Link (liblist, objlist , driver);
693
703
}
694
704
return exitStatus;
695
705
}
0 commit comments