码迷,mamicode.com
首页 > 其他好文 > 详细

VS Code配置链接库文件

时间:2020-11-01 10:25:37      阅读:61      评论:0      收藏:0      [点我收藏+]

标签:active   led   command   comm   语言   错误   命令   usr   basename   

配置VS code在C语言中调用gsl库文件
先确认gsl库,gcc都已正确安装,命令行
g++ -L/usr/local/lib hello.c -o hello -lgsl -lgslcblas -lm
没有错误则可以配置VS code

tasks.json要配置args字段
launch.json要配置environment字段
c_cpp_properties.json要配置includePath字段

tasks.json

{
	"version": "2.0.0",
	"tasks": [
		{ "type": "shell",
			"label": "C/C++: g++ build active file",
			"command": "/usr/bin/g++",
			"args": [
				      "-g",
				      "${file}",
            			      "-L/usr/local/lib",
	                       	      "-lgsl", "-lgslcblas", "-lm",
				      "-o",
                                      "${fileDirname}/${fileBasenameNoExtension}"
        			],

launch.json

    "cwd": "${workspaceFolder}",
            "environment": [
            {
                "name":  "LD_LIBRARY_PATH",
                "value": "/usr/local/lib",
            }

c_cpp_properties.json

            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include/gsl"
            ],

主文件hello.c编译链接成功

#include<stdio.h>
#include<gsl/gsl_sf_bessel.h>

int main()
{    
    double x1 = 5.0;
    double y1 = gsl_sf_bessel_J0(x1);
    printf("J0(%g) = %.18e\n", x1, y1);

    return 0;
}

VS Code配置链接库文件

标签:active   led   command   comm   语言   错误   命令   usr   basename   

原文地址:https://www.cnblogs.com/cdef/p/13907281.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!