kevinboone / solunar2

A command-line utility for Linux, for display sunrise/set and similar information
GNU General Public License v3.0
19 stars 4 forks source link

Error while building solunar2 in Mac #6

Closed lulunac27a closed 5 months ago

lulunac27a commented 11 months ago

I get an error while building this program after running make install command on Mac. I'm using MacOS 14.0. Program output:

src//program.c src//program_context.c src//main.c
make -C klib
cc -O3 -fpie -fpic -Wall -Werror -DNAME=\"klib\" -DVERSION=\"0.0.1\" -DSHARE=\"\" -DPREFIX=\"\" -I include  -MD -MF build//numberformat.deps -c -o build//numberformat.o src//numberformat.c
src//numberformat.c:195:25: error: format specifies type 'long' but the argument has type 'int64_t' (aka 'long long') [-Werror,-Wformat]
    sprintf (in, "%ld", n);
                  ~~~   ^
                  %lld
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/secure/_stdio.h:47:56: note: expanded from macro 'sprintf'
  __builtin___sprintf_chk (str, 0, __darwin_obsz(str), __VA_ARGS__)
                                                       ^~~~~~~~~~~
1 error generated.
make[1]: *** [build//numberformat.o] Error 1
make: *** [solunar] Error 2
kevinboone commented 5 months ago

I'm sorry about the slow reply. I removed the '-Werror' flag because different versions of GCC have different levels of fussiness about warnings.

lulunac27a commented 5 months ago

I still get an error when I use make, make install or sudo make install when I update the version:

echo src//program.c src//program_context.c src//main.c
src//program.c src//program_context.c src//main.c
make -C klib
make[1]: `klib.a' is up to date.
make -C libsolunar
make[1]: `libsolunar.a' is up to date.
cc -s -Wl,--gc-sections  -o solunar build//program.o build//program_context.o build//main.o libsolunar/libsolunar.a klib/klib.a -lm
ld: warning: -s is obsolete
ld: unknown options: --gc-sections
clang: error: linker command failed with exit code 1 (use -v to see invocation)
kevinboone commented 5 months ago

I think you're using clang, rather than traditional gcc. I haven't tested with clang, and I'm not sure it will work. From the documentation, it looks as if the clang equivalent of --gc-sections is -dead_strip. I don't know what the equivalent of '-s' is, if there is one.

--gc-sections is used in conjuction with -ffunc-sections to remove unused functions from the final executable. That potentially matters a little, because I'm used library code in this utility, from which not all functions are actually used. Rather than -s you could just run 'strip' on the resulting binary -- both will remove debug symbols.

If you just want something that works, you could remove both these offending switches, and the code should still run the same -- it will just be larger than it should be.

Sorry, support for clang isn't really on my radar yet.