VS Code配置链接库文件
Posted cdef
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VS Code配置链接库文件相关的知识,希望对你有一定的参考价值。
配置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
", x1, y1);
return 0;
}
以上是关于VS Code配置链接库文件的主要内容,如果未能解决你的问题,请参考以下文章