Undefined reference to `DAQmxCreateTask#8 not able to link DLL VS codes - c

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

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"
}

Related

Run bat file with npx command in visual code

I am getting this error in visual studio code:
The above error shows whenever I launch my progam due to this launch.json script:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Attach using Process Id",
"type": "python",
"request": "attach",
"processId": "${command:pickProcess}",
"justMyCode": true,
"preLaunchTask": "kill_process"
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"preLaunchTask": "kill_process"
}
]
}
And here is my tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": [
"$tsc"
],
"group": "build",
"label": "tsc: build - tsconfig.json"
},
{
"label": "kill_process",
"type": "shell",
"command": ".\\script\\kill_process.bat"
}
]
}
This is the content of kill_process.bat file:
npx kill-port 8000
However, when I run the script from powershell it executes without any problem, here is the proof:
Does someone perhaps know how I can run the kill_process.bat file without any error in visual studio code?
Strangely it is now fixed but I don't know how because now I am reading this in my console in visual studio code:
* Executing task: .\script\kill_process.bat
D:\documents\leerplek\python\Wpark>npx kill-port 8000
Process on port 8000 killed
* Terminal will be reused by tasks, press any key to close it.

link c files in vscode in linux show mistake : cc1: error: output filename specified twice

this is my launch.json
{
"version": "0.2.0",
"program": "${workspaceFolder}/pc",
"configurations": []
}
this is my task.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cpp 生成活动文件",
"command": "/usr/bin/cpp",
"args": [
"-fdiagnostics-color=always",
"-g",
"${workspaceFolder}/*.c", //这里是我修改的位置,修改后便提示如题所述的错误
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-lpthread"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
In the args of the task, I changed "${file}" to "${workspaceFolder}/*. c", and tried to use the command line to include all c files under the folder
In the launch, I added the setting option of "program" according to the guidance file, but I don't understand what it is for
Unable to use IDE due to course requirements
In addition, it should be mentioned that the code will disappear and display as two lines of address after the code reports an error (too low reputation to send a picture)

Visual Studio Code doesn't populate the Problems tab when I try to debug multiple files

HeIIo. This is my first post on Stackoverflow.
I like computer programming and after some experience with Python and VBA I'm trying to learn the C.
Since I took up with it I use Visual Studio Code for training in order to learn how to use modern programming tools at the same time.
I've never had any problem until now, but at the moment I want to compile multiple files.
When I try to compile a file with a warning the terminal shows it
Executing task: C:/mingw-w64/mingw64/bin/gcc.exe -Wall -W -pedantic -ansi -std=c99 -O -g 'd:\OneDrive\Programmi\C\Kim_N_King-Programmazione_in_C\Capitolo 19\stackADT\stackclient.c' 'd:\OneDrive\Programmi\C\Kim_N_King-Programmazione_in_C\Capitolo 19\stackADT\stackADT3.c' -o 'd:\OneDrive\Programmi\C\Kim_N_King-Programmazione_in_C\Capitolo 19\stackADT\stackADT.exe'
d:\OneDrive\Programmi\C\Kim_N_King-Programmazione_in_C\Capitolo 19\stackADT\stackADT3.c: In function 'is_full':
d:\OneDrive\Programmi\C\Kim_N_King-Programmazione_in_C\Capitolo 19\stackADT\stackADT3.c:41:20: warning: unused parameter 's' [-Wunused-parameter]
bool is_full(Stack s) {
~~~~~~^
but in the "Problems" tab it's not shown
(see the screenshot).
In every other folder where there is only a .c file to compile it works flawlessly.
The followings are my jsons file from which you can easily understand my VSC configuration and platform.
Thank you for reading.
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/mingw-w64/mingw64/bin/gcc.exe",
"cStandard": "c99",
"cppStandard": "c++17",
"intelliSenseMode": "${default}"
}
],
"version": 4
}
launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\stackADT.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\mingw-w64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "gcc.exe build active file"
}
]
}
tasks.json
{
"tasks": [
{
"type": "shell",
"label": "gcc.exe build active file",
"command": "C:/mingw-w64/mingw64/bin/gcc.exe",
"args": [
"-Wall",
"-W",
"-pedantic",
"-ansi",
"-std=c99",
"-O",
"-g",
"${file}",
"${fileDirname}\\stackADT3.c",
"-o",
"${fileDirname}\\stackADT.exe"
],
"options": {
"cwd": "C:/mingw-w64/mingw64/bin"
}
}
],
"version": "2.0.0"
}
It happens because you compile with flag "-Wall". It means that all warnings will be considered errors. You should use this variable.
for instance
(void*) &s;

I need some help regarding writing C code in vscode in wsl

I downloaded the gcc compiler into my linux environment and used ssh to get into vscode to simulate a linux environment on my windows machine. The files I have created compile and the makefile my professor gave me works fine, however whenever I go to debug using the gdb debugger my professor also provided, which is formatted correctly, the debugger hangs and doesnt allow me to step through my code with break points. I'm providing the code for the debugger as well as the cpp properties and the task files.
debugger code:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc build debug stacks",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/runner",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "make stack runner"
}
]
}
cpp properties:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
tasks:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "make stack runner",
"command": "make -f makefile DEBUG=1",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": [
"$gcc"
]
},
]
}
I don't think you require the tasks as cpp_properties. I'm able to use debug perfectly fine on WSL with only the launch.json file (The debugger code you mentioned) which I will give but I'm sure your problem will be solved if
1) Set externalConsole option as false. For some reason, it is not working in windows when set to "true". With this option, your program will run in the integrated console so you can be tricked into thinking that your program is not running if your program has no outputs before the first scanf() or cin command and your breakpoints are after them. So to be sure, have your breakpoints at the first line of your main() function, so that you don't make this classic newbie mistake.
2) Make sure when you compile the program you are using the -g switch. So your compile command should look like
gcc -g path\to\prog.cpp -o a.out
3) Make sure your program is set to the path of this executable file. If this a.out is generated at the root folder of your workspace, then your setting will be
"program":"${workspaceFolder}/a.out"
That should do.
My launch.json setting is
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "WSL debugging",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

The program 'c:\...\a.exe' has exited with code 0 (0x00000000)

I'm new to vscode editor and I want to run simple C project like below, but when I was run this debug console says like below. I want to know how to run this proper way.
Type "apropos word" to search for commands related to "word".
=cmd-param-changed,param="pagination",value="off"
[New Thread 3076.0x2314]
[New Thread 3076.0x20c4]
Thread 1 hit Breakpoint 1, 0x00401603 in main ()
[Thread 3076.0x20c4 exited with code 0]
[Inferior 1 (process 3076) exited normally]
The program 'c:\Users\Lenovo\Desktop\Example\a.exe' has exited with code 0 (0x00000000).
(this is test.c file )
#include <stdio.h>
int main()
{
printf("hellow world");
return 0;
}
I was configured tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "build Hello"
}
]
}
And this is launch.json code I was configured:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/MinGW/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
This is my c_cpp_properties.json file:
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/test.c",
"C:/MinGW/lib/gcc/i686-w64-mingw32/7.2.0/include/c++",
"C:/MinGW/lib/gcc/i686-w64-mingw32/7.2.0/include/c++//tr1",
"C:/MinGW/lib/gcc/i686-w64-mingw32/7.2.0/include/c++/i686-w64-mingw32"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceFolder}/test.c",
"C:/MinGW/lib/gcc/i686-w64-mingw32/7.2.0/include/c++",
"C:/MinGW/lib/gcc/i686-w64-mingw32/7.2.0/include/c++//tr1"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
It's just trying to tell you that all went fine. Return value 0 is "no error".
You have a typo in "hello" though, the trailing "w" shouldn't be there.
And main()'s parameters should be either (void) or (int argc, char *argv[]).

Resources