* linking qsort with gfortran
@ 2012-12-22 0:58 dlr13
2012-12-22 12:15 ` Tim Prince
2012-12-22 14:43 ` Ángel González
0 siblings, 2 replies; 3+ messages in thread
From: dlr13 @ 2012-12-22 0:58 UTC (permalink / raw)
To: gcc-help
First, apologies if this question has been answered elsewhere or I am doing something really stupid. I have searched for several hours for a solution to my problem with no success.
I am trying to do a GCC build of a mix of C and Fortran source that has been successfully compiled for many years with both the PGI and Intel compilers. I have one Fortran routine that calls "qsort", a sorting routine provided in most libraries. I know it is provided in the GCC libraries. However, because the call is from Fortran code, it will properly link with the library and I get this error:
Undefined symbols for architecture x86_64:
"_qsort_", referenced from:
I understand that the trailing underscore is the problem, but I cannot use the "no-underscoring" compiler flags because the code also links to other libraries that do provide the underscore which then breaks everything else. I am using gfortran to do the linking though I get the same error with gcc. I am using version 4.8 currently but get the same error with 4.7. Everything is on OS X, 10.7.
Any help would be greatly appreciated. Thank you.
_____
David
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: linking qsort with gfortran
2012-12-22 0:58 linking qsort with gfortran dlr13
@ 2012-12-22 12:15 ` Tim Prince
2012-12-22 14:43 ` Ángel González
1 sibling, 0 replies; 3+ messages in thread
From: Tim Prince @ 2012-12-22 12:15 UTC (permalink / raw)
To: gcc-help
On 12/21/2012 7:58 PM, dlr13@mac.com wrote:
> First, apologies if this question has been answered elsewhere or I am doing something really stupid. I have searched for several hours for a solution to my problem with no success.
>
> I am trying to do a GCC build of a mix of C and Fortran source that has been successfully compiled for many years with both the PGI and Intel compilers. I have one Fortran routine that calls "qsort", a sorting routine provided in most libraries. I know it is provided in the GCC libraries. However, because the call is from Fortran code, it will properly link with the library and I get this error:
>
> Undefined symbols for architecture x86_64:
> "_qsort_", referenced from:
>
> I understand that the trailing underscore is the problem, but I cannot use the "no-underscoring" compiler flags because the code also links to other libraries that do provide the underscore which then breaks everything else. I am using gfortran to do the linking though I get the same error with gcc. I am using version 4.8 currently but get the same error with 4.7. Everything is on OS X, 10.7.
>
> Any help would be greatly appreciated. Thank you.
>
> _____
> David
>
>
>
>
If there is no Fortran wrapper for qsort in your library you should be
able to call it via iso_c_binding. qsort isn't in a gcc library,
usually it's glibc, although I don't know mac specifics.
--
Tim Prince
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: linking qsort with gfortran
2012-12-22 0:58 linking qsort with gfortran dlr13
2012-12-22 12:15 ` Tim Prince
@ 2012-12-22 14:43 ` Ángel González
1 sibling, 0 replies; 3+ messages in thread
From: Ángel González @ 2012-12-22 14:43 UTC (permalink / raw)
To: dlr13; +Cc: gcc-help
On 22/12/12 01:58, dlr13@mac.com wrote:
> First, apologies if this question has been answered elsewhere or I am doing something really stupid. I have searched for several hours for a solution to my problem with no success.
>
> I am trying to do a GCC build of a mix of C and Fortran source that has been successfully compiled for many years with both the PGI and Intel compilers. I have one Fortran routine that calls "qsort", a sorting routine provided in most libraries. I know it is provided in the GCC libraries. However, because the call is from Fortran code, it will properly link with the library and I get this error:
>
> Undefined symbols for architecture x86_64:
> "_qsort_", referenced from:
>
> I understand that the trailing underscore is the problem, but I cannot use the "no-underscoring" compiler flags because the code also links to other libraries that do provide the underscore which then breaks everything else. I am using gfortran to do the linking though I get the same error with gcc. I am using version 4.8 currently but get the same error with 4.7. Everything is on OS X, 10.7.
>
> Any help would be greatly appreciated. Thank you.
>
> _____
> David
I would just add a C file wrapping one to the other:
#include <stdlib.h>
void qsort_(void *base, size_t nmemb, size_t size, int (*compar)(const
void *, const void *)) {
return qsort(base, nmemb, size, compar);
}
It is possible to make _qsort_ an alias for _qsort, but it would take me
more time to dig the reference than making such stub :)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-12-22 14:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-22 0:58 linking qsort with gfortran dlr13
2012-12-22 12:15 ` Tim Prince
2012-12-22 14:43 ` Ángel González
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).