我已按照提供的安装GSL-1.16库的说明进行操作,我认为我已成功安装了该库。但是,当我尝试编译&运行网站上的示例程序(http://www.gnu.org/software/gsl/manual/html_node/An-Example-Program.html#An-Example-Program)我收到以下消息:
$ gcc besel_exam.c
Undefined symbols for architecture x86_64:
"_gsl_sf_bessel_J0", referenced from:
_main in besel_exam-72d841.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
操作系统是macOS X Yosemite,gcc --version的输出如下:
$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
答案 0 :(得分:2)
确实,正如@trojanfoe和@bergercookie所说,你必须编译你的文件然后将它链接到库。正如Use WM_COPYDATA to send data between processes和compile中所述,针对该特定示例:
首先编译文件:
gcc -Wall -I/usr/local/include -c example.c -o example.o
第二,将其链接到库:
gcc -L/usr/local/lib example.o -lgsl -o example.e
当然,/ usr / local / lib应替换为安装了gsl的路径。
编辑:在macOS中,来自优胜美地的安装的默认位置是/opt/local/lib
(和/opt/local/include
)