gpt4 book ai didi

c++ - 在 CMake CMakeLists.txt 中添加对 NewT 的库引用

转载 作者:行者123 更新时间:2023-11-28 06:17:54 25 4
gpt4 key购买 nike

我正在尝试使用 newt 制作一个简单的 TUI。我已经安装了 newt-dev 包:apt-get install libnewt-dev 我相信它安装正确,因为如果我使用 gcc 和以下命令进行构建,它就可以工作就好了:

gcc -o test main.cpp -lnewt

但是当我使用新的 CLion IDE 尝试使用 cmake 时,我的简单代码无法编译。以下是源代码、CMakeLists.txt 和编译器输出:

#include <newt.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char* argv[])
{

/* required variables and string */
int uiRows, uiCols;
const char pcText[] = "Welcome to Newt and FLOSS !!!";

/* initialization stuff */
newtInit();
newtCls();

/* determine current terminal window size */
uiRows = uiCols = 0;
newtGetScreenSize(&uiCols, &uiRows);

/* draw standard help and string on root window */
newtPushHelpLine(NULL);
newtDrawRootText((uiCols-strlen(pcText))/2, uiRows/2, pcText);

/* cleanup after getting a keystroke */
newtWaitForKey();
newtFinished();

return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.1)
project(TemparatureMonitoring)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_library(newt) #this does nothing!

set(SOURCE_FILES main.cpp)
add_executable(TemparatureMonitoring ${SOURCE_FILES})

编译器输出:

/opt/clion-1.0/bin/cmake/bin/cmake --build /home/saeid/.clion10/system/cmake/generated/9c100db8/9c100db8/Debug --target all -- -j 4
You have called ADD_LIBRARY for library newt without any source files. This typically indicates a problem with your CMakeLists.txt file
-- Configuring done
CMake Error: Cannot determine link language for target "newt".
CMake Error: CMake can not determine linker language for target: newt
-- Generating done
-- Build files have been written to: /home/saeid/.clion10/system/cmake/generated/9c100db8/9c100db8/Debug
make: *** [cmake_check_build_system] Error 1

我想我必须以某种方式添加对 newt 包的引用,但不知道该怎么做!所以基本上我正在为 CMakeLists.txt

寻找等同于 gcc-l 开关

最佳答案

除了我的评论之外,经过一点搜索,我认为您需要命令“target_link_libraries” http://www.cmake.org/cmake/help/v3.0/command/target_link_libraries.html

关于c++ - 在 CMake CMakeLists.txt 中添加对 NewT 的库引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29881241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com