Im using VS codes to build a C program, i need to use a third party DLL from National instruments I have included the .h file in my program "NIDAQmx.h", but still when i run the program, the functions in this DLL is undefined How can i link this DLL to my code?
my code goes like this
#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 ");
}`
this is my console output
[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`
I tried giving path to the DLL like this
PS D:\VSCODES> code --add "C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib32\msvc\NIDAQmx.lib"
but its giving error
`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`
as suggested by one forum, i tried editing my tasks.json file
{
"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"
}
but this also didn't help
as suggested by answer i tried giving build in VS code terminal
but it returned error
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
I also changed the Task.json file, but still same error
CodePudding user response:
You can try specifying the library path in the command line you use to build the project:
gcc test.c -o test -L"C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib32\msvc" -lNIDAQmx.lib
Also your tasks.json
file is not well-formed. Could you please try this:
{
"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"
}
Here is your original tasks.json
file with additional parameters:
{
"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"
}