使用 gsl 进行 g++ 编译:找不到库

g++ compilation with gsl: library not found

您好,我正在尝试按照本指南安装和使用 GSL 库:Install GSL on Mac. The brew installation works fine and I can see the file in path: /usr/local/include. Then I tried with the sample c code, but when I compile it gives me this error: symbol(s) not found for architecture x86_64. I searched and referred to this answer here: g++ error,所以我在命令中添加了 -lgsl,例如:

g++ -I/usr/local/include -lgsl main.c

但它给出:ld: library not found for -lgsl 错误。我该如何解决这个问题?谢谢!

是的,解决方案应该是这样的:

g++ -I/usr/local/include -L/usr/local/lib -lgsl main.c

这行得通。参考这里的答案:Install GSL。基本上 -I 给你的是 headers,而我们还需要 -L 语句 link 库。