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

undefined reference to `integrate_quad_func_' #4

Closed
WangYun1995 opened this issue Dec 1, 2020 · 13 comments
Closed

undefined reference to `integrate_quad_func_' #4

WangYun1995 opened this issue Dec 1, 2020 · 13 comments

Comments

@WangYun1995
Copy link

WangYun1995 commented Dec 1, 2020

Hello,
I met one problem when I tested the functionality of scifor.
The code snippet is shown below.

 program test
  Use scifor
  Implicit None
  
  real(8) :: Integral

  Call quad_func(sin2, 0.0d0, pi, Integral)
  
  Write (*,*) Integral

! ------------------------------- !  
Contains
  Function sin2(x)
    Real(8) :: sin2
	Real(8) :: x
	
	sin2 = sin(x)**2
  End Function
end Program test

After I input directives gfortran test_integrate.f95 -I/home/wangy/opt/scifor/gnu/4.6.31/include -L/home/wangy/opt/scifor/gnu/4.6.31/lib -lscifor /usr/lib64/liblapack.so /usr/lib64/libblas.so ,
it returned me an error information which is shown below.

/tmp/ccbOEfEL.o: In function `MAIN__':
test_integrate.f95:(.text+0x8c): undefined reference to `integrate_quad_func_'
collect2: error: ld returned 1 exit status

How to solve this probelm?

@aamaricci
Copy link
Owner

The quad interface is a subroutine so the correct program is:
program test
Use scifor
Implicit None
real(8) :: Integral
call quad(sin2, 0.0d0, pi, result=integral)
Write (,) Integral
! ------------------------------- !
Contains
Function sin2(x)
Real(8) :: sin2
Real(8) :: x
sin2 = sin(x)**2
End Function sin2
end Program test

$ mpif90 $(pkg-config --cflags --libs scifor) test.f90
$ ./a.out
1.5707963097588762

Cheers,
A

@WangYun1995
Copy link
Author

Thank you!
When I used the compile command (pkg-config --cflags --libs scifor) test.f95, it returned -bash: -I/home/wangy/opt/scifor/gnu/4.6.31/include: No such file or directory to me.

However, when I input gfortran test.f95 -I/home/wangy/opt/scifor/gnu/4.6.31/include -L/home/wangy/opt/scifor/gnu/4.6.31/lib -lscifor /usr/lib64/liblapack.so /usr/lib64/libblas.so,
it returned me ./a.out.

Why did I fail to use $(pkg-config --cflags --libs scifor) test.f95?

@aamaricci
Copy link
Owner

aamaricci commented Dec 1, 2020 via email

@WangYun1995
Copy link
Author

According to your advice, I follow instructions printed after the make post-install. But there is another issue shown below.
QQ图片20201202093941

Why is there a \; in /usr/lib64/liblapack.so\;/usr/lib64/libblas.so? I think the \; leads to the gfortran error. How to address it?

@aamaricci
Copy link
Owner

This looks like the pkg-config configuration file for SCIFOR is corrupted.
pkg-config report informations about linking (and other) directives for any installed library in the system. This is done by reading suitable configuration files specific to each library. Each such file is provided together with the library and placed in specific system directories, where pkg-config can find and read, as stored in the environment variable PKG_CONFIG_PATH. The file have the form <library_name>.pc

Together with SCIFOR we thus provide a scifor.pc file, which is created by Cmake during post-install step. To avoid getting access to system directory we place such file in your home under ~/.pkgconfig.d. This directory is then added to the PKG_CONFIG_PATH by one of the method listed after $make post-install. In this way you can always retrieve linking information no matter where you compile using the $(pkg-config --cflags --libs scifor) string.

In some cases (depending on the Linux distro) this file scifor.pc comes out corrupted. You need to fix it by removing the ;;/usr/lib64/libblas.so and replacing it with a space. There should be only one reference to lapack and one to blas.

Note that this string is generated by a CMake macro that we use to search Lapack/Blas library.

This should solve your problem.

Cheers,
A

@WangYun1995
Copy link
Author

WangYun1995 commented Dec 2, 2020

So how to remove the ;;/usr/lib64/libblas.so?

@aamaricci
Copy link
Owner

aamaricci commented Dec 2, 2020 via email

@WangYun1995
Copy link
Author

Thank you so much!

@band-a-prend
Copy link
Contributor

@aamaricci ,

string is generated by a CMake macro

It seems that issue could be resolved by placing

STRING(REPLACE ";" " " LAPACK_LIBRARIES ${LAPACK_LIBRARIES})

into cmake/BuildPkgConfigFile.cmake before IF statements. And I need to check if this replacement works as I has described issue in my system.

LAPACK_LIBRARIES returns paths to /usr/lib64/lapack.so;/usr/lib64/blas.so by cmake for lapack implementation installed in my case. Additional path from BLAS_LIBRARIES string just add one blas library /usr/lib64/blas.so path if available and doesn't cause problem.

But I didn't check if this replacement affects other cmake files later.

@aamaricci
Copy link
Owner

I see.
Thanks for pointing this out. I'll try to implement this in a separate branch. Should this works as expected we can integrate it in the stable version.

@band-a-prend
Copy link
Contributor

I will update my gentoo package (not ready yet) for scifortran and will make additionally tests with some example that uses blas.

At least for 4.7.4 with example for newton() (no blas of couse) there was no ld errors with double blas library linked.

@aamaricci
Copy link
Owner

Packaging for Linux distro would be a very welcome upgrade. Please let us know and thanks for trying.

@band-a-prend
Copy link
Contributor

STRING(REPLACE ";" " " LAPACK_LIBRARIES ${LAPACK_LIBRARIES})

It should be (quoted last variable)
STRING(REPLACE ";" " " LAPACK_LIBRARIES "${LAPACK_LIBRARIES}") otherwise ";" will be replaced with empty string.

I update my patch with some more common cases (remove duplicates) but need to scifor with lapack related example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants