I would like to use the GNU Scientific Library (GSL) while continuing to use the TextMate text editor but I had some compile issues when I compile the code in TextMate.
First of all, I use an M1 Mac (Ventura 13.0.1) and the GSL library is installed in : /usr/local/include/gsl
For trying the compilation, I took the most basic example and I compiled it with a very generic MakeFile.
Code :
#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>
int
main (void)
{
double x = 5.0;
double y = gsl_sf_bessel_J0 (x);
printf ("J0(%g) = %.18e\n", x, y);
return 0;
}
MakeFile :
CC = gcc
EXEC = PROG
SRC = $(wildcard *.c)
OBJ = $(SRC:.c=.o)
CFLAGS = -g -Wall
LIBS = -lm -lgsl -lgslcblas -I/usr/local/include/gsl
RM = rm -rf
all : $(EXEC)
%.o : %.c
$(CC) -o $@ -c $<
$(EXEC) : $(OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(LIBS) && time ./$(EXEC) && make clean
.PHONY : clean
clean :
rm -rf $(EXEC) && rm -rf *.o
Thankfully, if I compile with the macOS terminal, everything is OK. I also tried to compile my code in VS Code with the in-app Terminal and it works fine.
However, I am having some errors when trying to compile my program with TextMate using the MakeFile Bundle (see below). After hours of reading and trying to figure it out, I think the problem is that the compiler of TextMate is not the same as the macOS compiler and it works fine on the macOS terminal thanks to Rosetta. I'm not a specialist at all so I'm very not sure of what I say.
Here is the error code :
ld: warning: ignoring file /usr/local/lib/libgslcblas.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
...
Undefined symbols for architecture x86_64:
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [PROG] Error 1
I also tried to install the library via Homebrew and change the PATH in the MakeFile but, in TextMate, I had the same error message.
The reason why I post here is that I could not find any solution for the TextMate Editor and because it works properly with the native Terminal from macOS.
So, is there a way to fix this issue in TextMate (maybe in the MakeFile ? in the TextMate app directly ?) ? Again, I'm not a specialist and I really don't know how to fix this...
EDIT : I tried to reinstall the library by compiling the file using the following command :
./configure CC ="gcc -arch x86_64"
./make
...
And now, it works on TextMate but not on the macOS Terminal anymore... And I have, in the macOS terminal :
ignoring file /usr/local/lib/libgsl.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
...
Undefined symbols for architecture arm64:
...
ld: symbol(s) not found for architecture arm64
Which is the exact opposite of what I had before. Is there a way to compile the library in such a way that I can compile my program in both?
Thanks in advance!
OK, I found a solution that works for me.
For this to work, when you install the library via the ./configure
of the GSL package, you will have to precise multiple architectures and then the command to type in the terminal should be :
sudo ./configure CC="gcc -arch arm64 -arch x86_64"
By doing this, you should be able to compile your program in any IDE with the appropriate MakeFile that I wrote above because the library was built for several architectures.