尝试在CLion / CMake中构建共享库 [英] Trying to build shared library in CLion/CMake

查看:177
本文介绍了尝试在CLion / CMake中构建共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试下载并构建



如果我告诉它无论如何都会生成以下错误。 / p>



我一直在努力寻找答案为什么我需要一个可执行文件来构建库以及那些未定义的引用的含义。

解决方案

我不知道这是否是原因问题,但include命令应如下所示: include_directories($ {MyHeaders}) $ {MyHeaders} 将扩展变量 MyHeaders 并将其当前值传递给 include_directories 。否则,从字面上看,您将包括目录 MyHeaders


I've been trying to download and build the Stanford Library source files and build a library out of them to use for my own project using the CLion (IDE). I've been following instructions from this answer and my CMakeLists file looks like this:

cmake_minimum_required(VERSION 3.3)
project(Stanford)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_BUILD_TYPE Release)


file(GLOB MyHeaders "*.h" /stacktrace/"*.h" private/"*.h")
file(GLOB MySources "*.cpp" /stacktrace/"*.cpp" private/"*.cpp")
include_directories(MyHeaders)
add_library(Stanford SHARED ${MySources} ${MyHeaders})


target_include_directories (Stanford PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

When opening the run menu, I get the following:

If I tell it to build anyway I get the following errors.

I've been struggling to find out what why I need an executable to build a library and what those undefined references mean.

解决方案

I don't know if it's the cause of your problem, but include command should look like this: include_directories(${MyHeaders}). ${MyHeaders} will expand the variable MyHeaders and pass its current value to include_directories. Otherwise you are, literally, including directory MyHeaders.

这篇关于尝试在CLion / CMake中构建共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆