Clion,cMake和POCO [英] Clion, cMake and POCO

查看:860
本文介绍了Clion,cMake和POCO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新人到c ++和cmake这里。我决定测试cLion和cMake。我试图写一个简单的电子邮件客户端的命令行。其他来源告诉我,实现POP3和SMTP功能的最佳方法是使用POCO。不幸的是,cMake给我麻烦。 CLion附带的版本是3.2,但我的机器运行的版本是2.8。

new guy to c++ and cmake here. I decided to test out cLion and cMake. Im trying to write a simple email client for the command line. Other sources told me that the best way to implement a POP3 and SMTP functions would be to use POCO. Unfortunately, cMake is giving me trouble. the version that came with CLion is 3.2 but the version that my machine is running is 2.8.

~$ cmake --version
cmake version 2.8.12.2

第一个问题。我想我可以绕过这一点,只是安装POCO,并做同样的事情,我用于openssl,我也不得不下载。

First problem. I thought that I could bypass this by just installing POCO and doing the same thing that i used for openssl which i also had to download.

cMakeList.txt:

cMakeList.txt:

cmake_minimum_required(VERSION 3.0)
project(Email_Reader)

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

#included paths for openssl and POCO. 

INCLUDE_DIRECTORIES("/usr/include/openssl")
INCLUDE_DIRECTORIES("/usr/local/include/Poco/Net")

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

POCO的文档告诉我我需要至少3.0工作,但我觉得我有2个不同的cMake在我的机器上。请帮助

Documentation for POCO tells me that I need at least 3.0 to work but i feel i have 2 different cMake's on my machine. please help

推荐答案

您可以从以下位置获取最新的CMake版本:http://www.cmake.org/download/

You can get the latest CMake release from: http://www.cmake.org/download/

对于Linux,它是这个档案:http://www.cmake.org/files/v3.2/cmake-3.2.2.tar.gz

For Linux, it's this archive: http://www.cmake.org/files/v3.2/cmake-3.2.2.tar.gz

使用它的一个简单方法是将提取的文件放在 /opt/cmake/cmake-3.2 然后创建以下别名(例如〜/ .bash_aliases

An easy way to use it is to put the extracted files in /opt/cmake/cmake-3.2 then create the following aliases (e.g. in ~/.bash_aliases:

alias ccmake3='/opt/cmake/cmake-3.2/bin/ccmake'
alias cmake3='/opt/cmake/cmake-3.2/bin/cmake'
alias cmake3-gui='/opt/cmake/cmake-3.2/bin/cmake-gui'
alias cpack3='/opt/cmake/cmake-3.2/bin/cpack'
alias ctest3='/opt/cmake/cmake-3.2/bin/ctest'

已正确构建和安装POCO。
入门页面提供了执行此操作所需的所有信息。但是,基本上,您应该从这里获取资源并提取它们somehwere:

Then, make sure that you have properly built and installed POCO. The Getting Started page has all the information you need for doing that. But, basically, you should get the sources from here and extract them somehwere:

wget http://pocoproject.org/releases/poco-1.6.0/poco-1.6.0.tar.gz
tar xvfz poco-1.6.0.tar.gz
cd poco-1.6.0
mkdir -p cmake_build cmake_install/debug cmake_install/release
cd cmake_build
cmake3-gui ..

在CMake 3 GUI中, code>配置。在新窗口中,保留默认选项 Unix Makefiles ,然后单击完成。将出现一条错误消息(这很好),单击 OK

In the CMake 3 GUI, press Configure. In the new window, keep the default option Unix Makefiles and click on Finish. An error message should appear (which is fine), click Ok.

创建 Debug 版本,设置如下:

CMAKE_BUILD_TYPE     : Debug
CMAKE_INSTALL_PREFIX : the absolute path to "cmake_install/debug"



为了让您快速启动POCO, unckeck 所有选项,除了以下内容,必须启用

ENABLE_JSON
ENABLE_NET
ENABLE_UTIL
ENABLE_XML
POCO_STATIC

>

退出GUI,然后生成/安装POCO:

Quit the GUI, then build/install POCO:

make clean
make -j8
make install

现在,POCO应安装在 cmake_install / debug 中。要创建/安装其他版本,只需执行相同的过程,但将 中的调试替换为 Release RelWithDebInfo MinSizeRel (cf. CMake's doc )(同时,您必须更改安装目录)

Now, POCO should be installed in cmake_install/debug. To build/install the other versions, just do the same procedure, but replace Debug in CMAKE_BUILD_TYPE with Release, RelWithDebInfo or MinSizeRel (cf. CMake's doc) (also, you'll have to change the install directories)

最后,您可以在C ++项目中使用POCO。

Finally, you can use POCO in you C++ projects.

例如,您的 CMakeLists.txt 应该如下所示:

For instance, your CMakeLists.txt should look like this:

cmake_minimum_required(VERSION 3.0)

project(Email_Reader)

# define the project
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

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

# set the POCO paths and libs
set(POCO_PREFIX      "/path/to/cmake_install/debug") # the directory containing "include" and "lib"
set(POCO_INCLUDE_DIR "${POCO_PREFIX}/include")
set(POCO_LIB_DIR     "${POCO_PREFIX}/lib")
set(POCO_LIBS        "${POCO_LIB_DIR}/libPocoNetd.a"
                     "${POCO_LIB_DIR}/libPocoUtild.a"
                     "${POCO_LIB_DIR}/libPocoJSONd.a"
                     "${POCO_LIB_DIR}/libPocoXMLd.a"
                     "${POCO_LIB_DIR}/libPocoFoundationd.a"
                     "pthread")

# set the include path for the app
target_include_directories(Email_Reader PRIVATE "${POCO_INCLUDE_DIR}")
# link the app against POCO
target_link_libraries(Email_Reader "${POCO_LIBS}")

这篇关于Clion,cMake和POCO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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