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

Using ForColormap as a static library fails #21

Closed
vmagnin opened this issue Jan 25, 2024 · 6 comments
Closed

Using ForColormap as a static library fails #21

vmagnin opened this issue Jan 25, 2024 · 6 comments
Assignees
Labels
help wanted Extra attention is needed
Milestone

Comments

@vmagnin
Copy link
Owner

vmagnin commented Jan 25, 2024

@jchristopherson @gha3mi

System: Ubuntu 23.10, FreeBSD 14.0
Compiler: GFortran 13.2.0

I am now trying to use ForColormap as a static library (.a under Linux). I have written a toy.f90 minimalist program:

use forcolormap, only: Colormap, wp
type(Colormap) :: cmap

call cmap%set("cubehelix", 0.0_wp, 1.0_wp, 1024)
print *, "test"
end

ForColormap was configured with cmake -D BUILD_SHARED_LIBS=false .. before building and installing.
The .mod files are all in /usr/local/include/ and the two .a are in /usr/local/lib/.

But I can not compile my toy program with the -static option:

$ gfortran -static toy.f90 $(pkg-config --cflags --libs forcolormap)
/usr/local/bin/ld: /usr/local/lib/libforcolormap.a(colormap_class.f90.o): in function `__forcolormap_MOD_write_ppm_colorbar':
colormap_class.f90:(.text+0xc10): undefined reference to `__pnm_MOD___vtab_pnm_Format_pnm'
/usr/local/bin/ld: colormap_class.f90:(.text+0xf38): undefined reference to `__pnm_MOD_set_format'
/usr/local/bin/ld: colormap_class.f90:(.text+0xf90): undefined reference to `__pnm_MOD_set_pnm'
/usr/local/bin/ld: colormap_class.f90:(.text+0xfbe): undefined reference to `__pnm_MOD_export_pnm'
/usr/local/bin/ld: colormap_class.f90:(.text+0x10a7): undefined reference to `__pnm_MOD_set_format'
collect2: error: ld returned 1 exit status
@vmagnin vmagnin self-assigned this Jan 25, 2024
@vmagnin vmagnin added the bug Something isn't working label Jan 25, 2024
@vmagnin vmagnin added this to the 0.9 milestone Jan 25, 2024
@gha3mi
Copy link
Collaborator

gha3mi commented Jan 25, 2024

$ gfortran -static toy.f90 $(pkg-config --cflags --libs forcolormap)

I didn't test it yet, maybe need to add forimage as well? --libs forimage forcolormap

@gha3mi
Copy link
Collaborator

gha3mi commented Jan 25, 2024

This works on my system:

cd forcolormap
mkdir build && cd build
cmake -D BUILD_SHARED_LIBS=false ..
make
sudo make install
cd mytest
gfortran -static toy.f90 -L/usr/local/lib -I/usr/local/include -lforcolormap -lforimage

@vmagnin
Copy link
Owner Author

vmagnin commented Jan 25, 2024

Thanks a lot @gha3mi ,

I have advanced a lot thanks to your message.
The following compilation commands works:

gfortran -static toy.f90 -L/usr/local/lib -I/usr/local/include -lforcolormap -lforimage
gfortran -static toy.f90 $(pkg-config --cflags --libs forcolormap forimage)

The following compilation commands fails:

gfortran -static toy.f90 $(pkg-config --cflags --libs forcolormap)
gfortran -static toy.f90 $(pkg-config --cflags --libs forimage forcolormap)
gfortran -static toy.f90 -L/usr/local/lib -I/usr/local/include -lforimage -lforcolormap

I had tried to use --libs forimage forcolormap with pkg-config. This order seemed intuitive (first the dependency, then the library itself), although I also thought it was not important. But it fails. And the reverse order works: --libs forcolormap forimage (and same remark with your detailed command).

@gha3mi
Copy link
Collaborator

gha3mi commented Jan 25, 2024

fpm makes me forget all knowledge about that :)

I have added an uninstall target to CMake, providing the ability to use make uninstall. Perhaps you could also add it for forcolormap. See gha3mi/forimage#17 and the corresponding changes: gha3mi/forimage@f1b4056. The same approach can be applied to forcolormap.

@vmagnin
Copy link
Owner Author

vmagnin commented Jan 25, 2024

I have added an uninstall target to CMake, providing the ability to use make uninstall. Perhaps you could also add it for forcolormap. See gha3mi/forimage#17 and the corresponding changes: gha3mi/forimage@f1b4056. The same approach can be applied to forcolormap.

Good idea! I put it in my TODO list. There is also such a functionality in gtk-fortran:
https://github.com/vmagnin/gtk-fortran/blob/gtk4/cmake/cmake_uninstall.cmake.in

@vmagnin vmagnin closed this as completed Jan 25, 2024
@vmagnin vmagnin added help wanted Extra attention is needed and removed bug Something isn't working labels Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants