【发布时间】:2023-01-19 20:42:52
【问题描述】:
我试图交叉编译一种C代码与CMake里面操作系统使用VS代码. 但是由于将 (.so) 文件与项目链接时出错,我遇到了错误。我已经经历了很多解决方案,但未能运行该任务。 我的代码如下:
` #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 ");
} `
运行任务时出错
`[ 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. `
我修改了我的 CMakeLists.txt 如下:
` 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)
`
如果我删除与 NI DAQmx 代码相关的元素,则可以正常工作。
【问题讨论】:
标签: c visual-studio-code cmake nidaqmx linux-rt