gpt4 book ai didi

c++ - 如何在 ubuntu 的 vs 代码中链接 c++ 的 fftw3 库?

转载 作者:太空宇宙 更新时间:2023-11-04 12:09:23 26 4
gpt4 key购买 nike

我下载了 fftw3 tar 文件并解压缩并配置了它,并在 ~/usr/include/中进行了 make 和 make install

现在我写了一个简单的代码

#include<iostream>
#include <fftw3.h>
int main()
{
fftw_complex *T=(fftw_complex *)fftw_malloc(sizeof(fftw_complex)*5*5);
return 0;
}

然后我去了vs code的c_cpp_properties.json文件,更新了

{
"configurations": [
{
"name": "Mac",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
]
},
{
"name": "Linux",
"includePath": [
"/usr/include/c++/5",
"/usr/include/x86_64-linux-gnu/c++/5",
"/usr/include/c++/5/backward",
"/usr/lib/gcc/x86_64-linux-gnu/5/include",
"/usr/local/include",
"/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
"/usr/include/x86_64-linux-gnu",
"/usr/include",
"~/usr/include/",
"${workspaceRoot}"
],
"defines": ["_DEBUG"],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include/c++/5",
"/usr/include/x86_64-linux-gnu/c++/5",
"/usr/include/c++/5/backward",
"/usr/lib/gcc/x86_64-linux-gnu/5/include",
"/usr/local/include",
"/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
"/usr/include/x86_64-linux-gnu",
"/usr/include",
"~/usr/include/",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
},
{
"name": "Win32",
"includePath": [
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include",
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 3

你可以看到我添加了链接到 ~/usr/include在包含路径部分

现在还是报错

/tmp/ccBhp7Pq.o: In function `main':
Source1.cpp:(.text+0x11): undefined reference to `fftw_malloc'
collect2: error: ld returned 1 exit status

不知道现在该怎么办。在 ubuntu 16.04 中运行

最佳答案

Building your code Microsoft C/C++ VS Code 扩展部分说,如果你想构建你的应用程序,你必须将所有必需的参数添加到 “tasks.json” 中构建任务的“args”。

所以只需将 fftw 库名称和路径添加到参数中,例如:

...
"tasks": [
...
"args": [
...
"-lfftw3", "-L~/usr/lib"
]
]
...

关于c++ - 如何在 ubuntu 的 vs 代码中链接 c++ 的 fftw3 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49486880/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com