c++ - 在 Mac 10.6.3 上使用 gsl

标签 c++ macos precompiled-headers gsl

我最近有一个使用 GSL 的项目。在 Mac 10.6.3 上安装 GSL 包后。我无法编译我的代码。

gsl lib位于/usr/local/lib,头文件位于/usr/local/。

当我编译我的代码时,出现以下错误。如果我在 makefile 中不指定“-m32”,它仍然会给出相同的错误,只需将“i386”更改为“x86_64”即可​​。谁能帮我?

谢谢!

#include <gsl/gsl_vector.h>
#include <gsl/gsl_multiroots.h>

顺便说一句,我应该像上面那样包含gsl吗?实际上我对编程很陌生。

Undefined symbols for architecture i386:
"_gsl_vector_get", referenced from:
  gsl_root_finding::print_state(unsigned long, gsl_multiroot_fdfsolver*)in test_guide.o
  gsl_root_finding::print_state(unsigned long, gsl_multiroot_fsolver*)in test_guide.o
  gsl_root_finding::mm_f(gsl_vector const*, void*, gsl_vector*)in test_guide.o
  gsl_root_finding::process(int, double*, double, double)in test_guide.o
  gsl_root_finding::mm_fdf(gsl_vector const*, void*, gsl_vector*, gsl_matrix*)in test_guide.o
  gsl_root_finding::mm_df(gsl_vector const*, void*, gsl_matrix*)in test_guide.o
"_gsl_vector_set", referenced from:
  gsl_root_finding::mm_f(gsl_vector const*, void*, gsl_vector*)in test_guide.o
  gsl_root_finding::process(int, double*, double, double)in test_guide.o
  gsl_root_finding::mm_fdf(gsl_vector const*, void*, gsl_vector*, gsl_matrix*)in test_guide.o
  gsl_root_finding::mm_df(gsl_vector const*, void*, gsl_matrix*)in test_guide.o

ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
make: *** [test_guide] Error 1

构建代码:

CC = g++
OPT = -pg -g -I../include -L../libs -I../../Matrix-1.0/include -I../../bessel-1.1/include  -L../../Matrix-1.0/libs -L../../bessel-1.1/libs -L/usr/local/lib
LIBS =  -lfmm -lssi -lsparse -lbessel -lg2c -lgfortran -lgsl
.SUFFIXES : .o .cpp 

test_guide: test_guide.o
  ${CC} -o $@ ${OPT} test_guide.o ${LIBS} 

最佳答案

我不确定,但我认为您还需要链接到 GSL 的 BLAS 库。您的 x86_64 undefined reference 似乎暗示了很多(blas.o 是我要继续的提示)。只需添加

-lgslcblas

到您的 LIBS 变量。

关于c++ - 在 Mac 10.6.3 上使用 gsl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5921765/

相关文章:

c++ - GCC 和预编译 header

c++ - 有什么办法可以同时使用多个预编译头文件和 Clang?

c++ - 在运行时转换指针 [非平凡场景]

c++ - 调试嵌入式目标时使用了错误的 python 解释器

c - 使用Xcode跳转到StdLib源码

macos - 如何确定 Docker 容器(在 M1 MacBook 上)何时通过 qemu 运行?

c++ - 文件错误意外结束

c++ - 射线柱相交

c++ - 交叉编译 Ubuntu 到 Beaglebone 后无法在目标上找到共享库

macos - CGWindowListCopyWindowInfo、kCGWindowLayer 和窗口级别