1

我正在尝试使用 WiringPi 库通过 clion IDE 运行 c 程序。Hello world 运行良好,因此我可以确保与 pi 的连接已正确建立。但是,当我添加wiringPi-Library #include 并运行wiringPiSetup(); 我收到一条错误消息。

为了解决这个问题,我在 Clion/Preferences/Build、Execution、Deployment/CMake/Build 选项中添加了“-lwiringPi”。然而,这并没有改变什么。也许 CMakeLists.c 中缺少一些东西,但我实际上不知道是什么。

#include <stdio.h>
#include <wiringPi.h>

// Code I want to make running
int main() {
    wiringPiSetup();
    return 0;
}

错误信息:

=====================[构建| 写莫尔斯 | 远程调试]======================/usr/local/bin/cmake --build /tmp/tmp.tL61Mxt6gP/cmake-build-debug-远程 --target write_morse -- -j 4 [50%] 链接 C 可执行文件 write_morse CMakeFiles/write_morse.dir/main.co:在函数main': /tmp/tmp.tL61Mxt6gP/main.c:6: undefined reference towiringPiSetup' collect2:错误:ld 返回 1 退出状态 CMakeFiles/write_morse.dir/build.make :83:目标'write_morse'的配方失败make [3]:* [write_morse]错误1 CMakeFiles / Makefile2:72:目标'CMakeFiles / write_morse.dir / all'的配方失败make [2]:[CMakeFiles/write_morse.dir/all] 错误 2 CMakeFiles/Makefile2:84:目标“CMakeFiles/write_morse.dir/rule”的配方失败 make[1]:[CMakeFiles/write_morse.dir/rule] 错误 2 Makefile:118:目标“write_morse”的配方失败 make:* [write_morse] 错误 2

-lwiringPi 的错误消息:

=====================[构建| 写莫尔斯 | 远程调试]======================/usr/local/bin/cmake --build /tmp/tmp.tL61Mxt6gP/cmake-build-debug-远程 --target write_morse -- -lwiringPi [ 50%] 链接 C 可执行文件 write_morse CMakeFiles/write_morse.dir/main.co:在函数main': /tmp/tmp.tL61Mxt6gP/main.c:6: undefined reference towiringPiSetup'

CMakeList.txt

cmake_minimum_required(VERSION 3.14)
project(write_morse C)

set(CMAKE_C_STANDARD 99)

add_executable(write_morse main.c)
4

0 回答 0