首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能在m1 mac上包含gsl

不能在m1 mac上包含gsl
EN

Stack Overflow用户
提问于 2022-10-12 18:33:19
回答 1查看 85关注 0票数 0

不过,我已经成功地用homebrew安装了GSL库。

代码语言:javascript
复制
brew info gsl
==> gsl: stable 2.7.1 (bottled)
Numerical library for C and C++
https://www.gnu.org/software/gsl/
/opt/homebrew/Cellar/gsl/2.7.1 (290 files, 9.8MB) *
  Poured from bottle on 2022-10-12 at 19:30:40
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/gsl.rb
License: GPL-3.0-or-later
==> Analytics
install: 3,814 (30 days), 10,911 (90 days), 50,876 (365 days)
install-on-request: 1,590 (30 days), 4,514 (90 days), 22,602 (365 days)
build-error: 0 (30 days)

现在我想在VSCode中运行这个简单的程序,以确保库按预期工作,我在c_cpp_properties.json中添加了includePath,它不能正确地包含*.h

我的脚本

代码语言:javascript
复制
#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;
}

c_cpp_properties.json

代码语言:javascript
复制
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "/opt/homebrew/Cellar/gsl/2.7.1/include"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "macos-clang-arm64"
        }
    ],
    "version": 4
} 

tasks.json

代码语言:javascript
复制
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang build active file",
            "command": "/usr/bin/gcc",
            "args": [
                "-fcolor-diagnostics",
                "-fansi-escape-codes",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
} 

launch.json

代码语言:javascript
复制
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": []
} 

我收到错误消息fatal error: 'gsl/gsl_sf_bessel.h' file not found

EN

回答 1

Stack Overflow用户

发布于 2022-10-12 21:27:49

我设法用以下命令从命令行编译它:

代码语言:javascript
复制
gcc -Wall -I/opt/homebrew/include -c try.c
gcc -L/opt/homebrew/lib try.o -lgsl -lgslcblas -lm

此外,在VSCode中,必须相应地修改task.json,以便将库链接到包含路径。

task.json

代码语言:javascript
复制
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang build active file",
            "command": "/usr/bin/gcc",
            "args": [
                "-fcolor-diagnostics",
                "-fansi-escape-codes",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "-I/opt/homebrew/include",
                "-L/opt/homebrew/lib",
                "-lgsl",
                "-lgslcblas",
                "-lm"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

c_cpp_properties.json

代码语言:javascript
复制
{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/opt/homebrew/include"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "macos-clang-arm64"
        }
    ],
    "version": 4
}

编辑: c_cpp_properties.json实际上与此无关。task.json的论点很重要。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74046534

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档