未定义的对“DAQmxCreateTask@8”的引用无法链接DLL VS代码

t9aqgxwy  于 2023-01-16  发布在  其他
关注(0)|答案(1)|浏览(133)

我使用VS代码来构建C程序,我需要使用National Instruments的第三方DLL我已经将.h文件包含在我的程序“NIDAQmx. h”中,但当我运行程序时,此DLL中的函数仍未定义如何将此DLL链接到我的代码?
我的代码是这样的

#include<stdio.h>
#include"C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\include\NIDAQmx.h"

TaskHandle taskHandle=0;
int ret=0;

    void main()
{
    printf("Hello world");
    ret=DAQmxCreateTask("task",&taskHandle);
    printf("Return for creating task is %d\n",ret);
    DAQmxStopTask (taskHandle);
    DAQmxClearTask(taskHandle);
    printf("Task closed ");

}`

这是控制台输出

[Running] cd "d:\VSCODES\" && gcc test.c -o test && "d:\VSCODES      \"test C:\Users\rahul\AppData\Local\Temp\ccuN1dmO.o:test.c:(.text+0x32):       

undefined reference to `DAQmxCreateTask@8'

C:\Users\rahul\AppData\Local\Temp\ccuN1dmO.o:test.c:(.text+0x5c):        undefined reference to `DAQmxStopTask@4'

C:\Users\rahul\AppData\Local\Temp\ccuN1dmO.o:test.c:(.text+0x6c): undefined reference to `DAQmxClearTask@4'

collect2.exe: error: ld returned 1 exit status

[Done] exited with code=1 in 0.244 seconds`

我试着像这样给出DLL的路径

PS D:\VSCODES> code --add "C:\Program Files (x86)\National        Instruments\Shared\ExternalCompilerSupport\C\lib32\msvc\NIDAQmx.lib"

但它的给误差

`code : The term 'code' is not recognized as the name of a cmdlet,  function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

 At line:1 char:1
 + code --add "C:\Program Files (x86)\National Instruments\Shared  \Extern ...
+ ~~~~
+ CategoryInfo          : ObjectNotFound: (code:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException`

正如一个论坛建议的那样,我尝试编辑tasks.json文件

{
"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C++: gcc.exe build active file",
        "command": "C:\\MinGW\\bin\\gcc.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
            "-LC:\\"C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib32\msvc\NIDAQmx.lib"
            "-lNIDAQmx.lib",
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "Task generated by Debugger."
    }
],
"version": "2.0.0"
}

但这也没有帮助
正如答案所建议的,我尝试在VS代码终端中提供构建
但返回错误

PS D:\VSCODES> gcc test.c -o test -L"C:\Program Files (x86)\National    Instruments\Shared\ExternalCompilerSupport\C\lib32\msvc" -lNIDAQmx.lib

gcc.exe: error: .lib: No such file or directory

我还更改了Task.json文件,但仍然出现相同的错误

vkc1a9a2

vkc1a9a21#

可以尝试在用于生成项目的命令行中指定库路径:

gcc test.c -o test -L"C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib32\msvc" -lNIDAQmx.lib

此外,您的tasks.json文件格式不正确。请尝试以下操作:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe build active file",
            "command": "C:\\MinGW\\bin\\gcc.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-LC:\\Program Files (x86)\\National Instruments\\Shared\\ExternalCompilerSupport\\C\\lib32\\msvc\\NIDAQmx.lib",
                "-lNIDAQmx.lib"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

下面是带有附加参数的原始tasks.json文件:

{
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: gcc.exe build active file",
            "command": "C:\\MinGW\\bin\\gcc.exe",
            "args": [
                "-g",
                "test.c",
                "-o",
                "test.exe",
                "-LC:\\Program Files (x86)\\National Instruments\\Shared\\ExternalCompilerSupport\\C\\lib32\\msvc\\NIDAQmx.lib",
                "-lNIDAQmx.lib"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

相关问题