zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

Macos解决directory not found for option '-L/"

macos 解决 for not &# option found quot
2023-06-13 09:15:16 时间

问题

笔者在开发过程中遇到环境配置问题directory not found for option '-L/opt/homebrew/Cellar/librdkafka/1.9.2", 可是本地路径的librdkafka的正确路径是/opt/homebrew/Cellar/librdkafka/2.0.2,

解决办法

  1. 找到本机正确的gcc版本,如无则先安装, 如果是homebrew安装,则一般在/opt/homebrew/Cellar/gcc/路径下,笔者的gcc路径为-L/opt/homebrew/Cellar/gcc/12.2.0/lib/gcc/12
  2. 新建Make配置文件/Users/[username]/.R/Makevars, 添加如下内容
VER=-12.2.0
CC=gcc$(VER)
CXX=g++$(VER)
CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
FLIBS=-L/opt/homebrew/Cellar/gcc/12.2.0/lib/gcc/12

3. 重新Make,成功

原因分析

根据stackOverFlow上的答案https://stackoverflow.com/questions/35999874/mac-os-x-r-error-ld-warning-directory-not-found-for-option 该问题是因为本地在安装clang之后,编译命令被转发给了clang而非gcc,因此需要为Make提供正确的gcc参数,原英文解释如下

What is happening is your code is not being run under gcc instead it is being forwarded to clang
You will need to change your compile statements in ~/.R/Makevars/ to gcc using:

后记

笔者并非专门开发c/c++的程序员,仅记录此问题供自己后续查询以及帮到可能遇到相同问题的同行,c/c++环境的问题答案各异,具体问题还需具体分析