NOAA-EMC / NCEPLIBS-ip

Fortran 90 subprograms to be used for interpolating between nearly all grids used at NCEP.
Other
6 stars 9 forks source link

Compile code to be relocatable. #261

Open webisu opened 3 days ago

webisu commented 3 days ago

Compile with -fPIC to get relocatable code. Want to make a (relocatable) python library that uses iplib.

AlexanderRichert-NOAA commented 3 days ago

Do you need this through spack-stack? If you just need it for your own development copy of ip, then building with -DCMAKE_POSITION_INDEPENDENT_CODE=ON should do the trick (I assume you're compiling a static library).

webisu commented 16 hours ago

The goal is to make python call libwgrib2.so (import pywgrib2_s). This means that libraries that wgrib2 calls will have to be compiled with -fPIC.

On Fri, Nov 29, 2024 at 6:07 PM Alex Richert @.***> wrote:

Do you need this through spack-stack? If you just need it for your own development copy of ip, then building with -DCMAKE_POSITION_INDEPENDENT_CODE=ON should do the trick (I assume you're compiling a static library).

— Reply to this email directly, view it on GitHub https://github.com/NOAA-EMC/NCEPLIBS-ip/issues/261#issuecomment-2508724624, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEIB7ZV2W4JUEMQLILZM7MT2DDXR5AVCNFSM6AAAAABSX2MFM6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMBYG4ZDINRSGQ . You are receiving this because you authored the thread.Message ID: @.***>

AlexanderRichert-NOAA commented 11 hours ago

Have you already tried -DCMAKE_POSITION_INDEPENDENT_CODE=ON for wgrib2? If that doesn't work then that's probably a cmake bug for wgrib2.

webisu commented 10 hours ago

I got all the netcdf, hdf5, g2c, png, jasper, openjpeg, aec libraries to work. IP was the only exception. I can make wgrib2 when I turned off MAKE_SHARED_LIB in wgrib2.

On Mon, Dec 2, 2024 at 1:59 PM Alex Richert @.***> wrote:

Have you already tried -DCMAKE_POSITION_INDEPENDENT_CODE=ON for wgrib2? If that doesn't work then that's probably a cmake bug for wgrib2.

— Reply to this email directly, view it on GitHub https://github.com/NOAA-EMC/NCEPLIBS-ip/issues/261#issuecomment-2512464147, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEIB7ZX4SS4FRHSDGGJ7EPL2DSUYBAVCNFSM6AAAAABSX2MFM6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMJSGQ3DIMJUG4 . You are receiving this because you authored the thread.Message ID: @.***>

AlexanderRichert-NOAA commented 10 hours ago

To investigate further I'll need exact steps to reproduce the problem, please.

webisu commented 9 hours ago

How I tell whether .a is relocatable: $ ar x libip_4.a $ gcc -shared -o libtest.so .o Complaints about -fPIC.

I built ip by: git clone "https://github.com/NOAA-EMC/NCEPLIBS-ip" cd NCEPLIB-ip edit CMakeLists.txt change option(OPENMP "Use OpenMP threading" OFF) to option(OPENMP "Use OpenMP threading" ON) mkdir build cd build make sudo make install

On Mon, Dec 2, 2024 at 2:56 PM Alex Richert @.***> wrote:

To investigate further I'll need exact steps to reproduce the problem, please.

— Reply to this email directly, view it on GitHub https://github.com/NOAA-EMC/NCEPLIBS-ip/issues/261#issuecomment-2512642404, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEIB7ZUY6JOKWLW6EXOSSN32DS3M5AVCNFSM6AAAAABSX2MFM6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMJSGY2DENBQGQ . You are receiving this because you authored the thread.Message ID: @.***>

AlexanderRichert-NOAA commented 9 hours ago

I don't see the cmake step-- are you using -DCMAKE_POSITION_INDEPENDENT_CODE=ON? i.e., cmake .. -DCMAKE_POSITION_INDEPENDENT_CODE=ON?

webisu commented 8 hours ago

No. So I have to make a non-default version of IP.

On Mon, Dec 2, 2024 at 3:54 PM Alex Richert @.***> wrote:

I don't see the cmake step-- are you using -DCMAKE_POSITION_INDEPENDENT_CODE=ON? i.e., cmake .. -DCMAKE_POSITION_INDEPENDENT_CODE=ON?

— Reply to this email directly, view it on GitHub https://github.com/NOAA-EMC/NCEPLIBS-ip/issues/261#issuecomment-2512808515, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEIB7ZQFLYY6ITPJBK4P6ML2DTCJ5AVCNFSM6AAAAABSX2MFM6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMJSHAYDQNJRGU . You are receiving this because you authored the thread.Message ID: @.***>

AlexanderRichert-NOAA commented 8 hours ago

Correct, it'll require either explicit PIC with the above build option, or building the shared version.