HydrologicEngineeringCenter / hec-dss

source code for HEC-DSS (Data Storage System)
MIT License
27 stars 8 forks source link

Fix: compilation in linux #260

Open Atreyagaurav opened 2 weeks ago

Atreyagaurav commented 2 weeks ago

I couldn't compile the hec-lib on Linux, so I have fixed some of the issues. These are minor changes that should not break anything but please do check compiling it on other platforms with this before merging.

sonarcloud[bot] commented 2 weeks ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

Atreyagaurav commented 2 weeks ago

For more context: The compilation failed with the following error on Arch Linux for strcasestr function, so this fix prevents it from being redefined:

src/Utilities/verticalDatum.c:43:13: error: conflicting types for ‘strcasestr’; have ‘const char *(const char *, const char *)’
   43 | const char* strcasestr(const char* haystack, const char* needle) {
      |             ^~~~~~~~~~
In file included from src/Utilities/verticalDatum.c:2:
/usr/include/string.h:380:14: note: previous declaration of ‘strcasestr’ with type ‘char *(const char *, const char *)’
  380 | extern char *strcasestr (const char *__haystack, const char *__needle)
      |              ^~~~~~~~~~
make[1]: *** [Makefile:35: Output/./src/Utilities/verticalDatum.c.o] Error 1
make[1]: Leaving directory '/home/.../hec-dss/heclib/heclib_c'
make: *** [Makefile:25: all] Error 2
ktarbet commented 1 week ago

Hi @Atreyagaurav , thanks for posting.

Do the tests all pass with your change on your OS?

Based on the error message, It might work to remove the const keyword in verticalDatum.c

from:

const char* strcasestr(const char* haystack, const char* needle) 

to:

char* strcasestr(const char* haystack, const char* needle) 
Atreyagaurav commented 1 week ago

Do the tests all pass with your change on your OS?

I tried without my change and with my change, both cases I get an error on one test case, but this seems to be related to test/C/v6-pc.dss file.

Exact Terminal Output is here ``` ( cd ../test/C; mkdir -p Output; ./unix_test) os = Linux ../../heclib//Output/heclib.a -m64 -c -fPIC -g -std=gnu99 -I../../heclib/heclib_c/src/headers rm: cannot remove './Output/*': No such file or directory cp: cannot stat '../../dss-test-data/*.dss': No such file or directory endian.c running endian your system is: Little endian Data types and sizes int 4 int* 8 float 4 float* 8 double 8 double* 8 long 8 long long 8 long long* 8 void* 8 char 1 char* 8 ts_readv6.c running ts_readv6 Test_Error with ts_readv6 17:28:52.453 -----DSS---zopen New file opened, File: v6-pc.dss 17:28:52.453 Handle 3; Process: 3377; DSS Version: 7-IU 17:28:52.453 Single-user advisory access mode 17:28:52.453 =====DSS===Debug: zpermRead; Handle: 3 17:28:52.453 =====DSS===Debug: zpermRead; Handle: 3 17:28:52.453 =====DSS===Debug: zpermRead; Handle: 3 17:28:52.453 =====DSS===Debug: zpermRead; Handle: 3 17:28:52.453 =====DSS===Debug: zpermRead; Handle: 3 17:28:52.453 =====DSS===Debug: zpermRead; Handle: 3 17:28:52.453 -----DSS--- ztsRetrieveReg Warning: Invalid date or time given. 17:28:52.453 17:28:52.453 17:28:52.453 /BOISE RIVER/LUCKYPEAK/STORAGE//1DAY/OBS/ 17:28:52.453 Pathname: /BOISE RIVER/LUCKYPEAK/STORAGE//1DAY/OBS/ 17:28:52.453 File v6-pc.dss ztsRetrieve.status= -200424799 ts_write_irregular.c running ts_write_irregular ExampleSecondGranularity.c running ExampleSecondGranularity SampleText1.c running SampleText1 SamplePairedData.c running SamplePairedData ExampleMinuteGranularity.c running ExampleMinuteGranularity ts_write.c running ts_write ExampleTimeSeries1.c running ExampleTimeSeries1 ExampleTimeSeries2.c running ExampleTimeSeries2 GridTest.c running GridTest GridTest.dss: data GridTest.c running GridTest zopenExample.c running zopenExample ============= Native Test Summary ============ C test program run is finished 13 tests found 12 tests successful 1 tests failed Failed make: *** [Makefile:53: test] Error 255 ```

Based on the error message, It might work to remove the const keyword in verticalDatum.c

That doesn't work either, I get error: return discards ‘const’ qualifier from pointer target type. Plus if the function is already defined in strings.h, I think it's best to remove it using preprocessor. Although I don't know if different linux distro have different versions of strings.h (with and without this function), if it has been working so far in linux distro you guys have tested on, it could be because of that reason.

Full output ``` (cd heclib_c; make ) make[1]: Entering directory '/home/.../heclib/heclib_c' mkdir -p Output/./src/Utilities/ cc -c -m64 -fPIC -g -std=gnu99 -Isrc/headers -Werror -D__linux__ -fcommon -c src/Utilities/verticalDatum.c -o Output/./src/Utilities/verticalDatum.c.o src/Utilities/verticalDatum.c: In function ‘strcasestr’: src/Utilities/verticalDatum.c:48:29: error: return discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers] 48 | return haystack + haystackPos; | ~~~~~~~~~^~~~~~~~~~~~~ cc1: all warnings being treated as errors make[1]: *** [Makefile:35: Output/./src/Utilities/verticalDatum.c.o] Error 1 make[1]: Leaving directory '/home/.../heclib/heclib_c' make: *** [Makefile:25: all] Error 2 ```