Linux RT-Unable to link .lib to VSCode-Undefined reference to `DAQmxCreateTask'

68 Views Asked by At

I was trying to cross compile a C code with CMake inside Linux RT using VSCode. But I am encountering an error due to the mistake in linking (.so) file with project. I have gone through many solutions but failed to run the task. My code is given below:

  #include<stdio.h>
  #include"/home/admin/helloworld/src/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 ");

  } 

Error while running the task.

[ 50%] Linking C executable bin/helloWorld   
CMakeFiles/helloWorld.dir/home/admin/helloworld/src/helloWorld.c.o: 
In function `main':/home/admin/helloworld/src/helloWorld.c:11: undefined reference to `DAQmxCreateTask'
/home/admin/helloworld/src/helloWorld.c:13: undefined reference to `DAQmxStopTask'
/home/admin/helloworld/src/helloWorld.c:14: undefined reference to `DAQmxClearTask'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/helloWorld.dir/build.make:95: bin/helloWorld] Error 1
make[1]: *** [CMakeFiles/Makefile2:68:CMakeFiles/helloWorld.dir/all] Error 2
*  The terminal process
"/bin/bash '-c', 'make'" failed to launch 
(exit code: 2). 
*  Terminal will be reused by tasks, press any key to close it.
         

I modified my CMakeLists.txt as follows:

  cmake_minimum_required(VERSION 3.7.2)
  # project settings
  project(helloWorld VERSION 0.1.0)
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin)
  set(CMAKE_GENERATOR "Unix Makefiles")
  # executable settings
  add_executable(helloWorld ../src/helloWorld.c)
  set(CMAKE_BUILD_TYPE Debug)
  LINK_LIBRARIES(NIDAQmx ../src/libnidaqmx.so)
                         

If I remove the elements associated with NIDAQmx code working properly.

0

There are 0 best solutions below