上篇文章 小记了:

关于 Poco::TCPServer框架 (windows 下使用的是 select模型) 学习笔记.

http://www.cnblogs.com/bleachli/p/4352959.html

这儿继续学习下,poco在linux 下用cmake 编译.

从文档开始编译出错

从poco的 README 文件上可知:

"

BUILDING ON UNIX/LINUX/MAC OS X
===============================

For building on Unix platforms, the POCO C++ Libraries come with their own
build system. The build system is based on GNU Make 3.80 (or newer), with the help 
from a few shell scripts. If you do not have GNU Make 3.80 (or later) installed on 
your machine, you will need to download it from 
http://directory.fsf.org/devel/build/make.html>, 
build and install it prior to building the POCO C++ Libraries.

You can check the version of GNU Make installed on your system with

> gmake --version

or

> make --version

Once you have GNU Make up and running, the rest is quite simple.
To extract the sources and build all libraries, testsuites and samples, simply

> gunzip poco-X.Y.tar.gz
> tar -xf poco-X.Y.tar
> cd poco-X.Y
> ./configure
> gmake -s

"

但一直觉得 cmake 比较简单,所以用cmake 编译.官网就命令就3句:

"

cmake .

make

make install

"

  make 的话是:

./configure --omit=Data/ODBC,Data/SQLite --prefix=/usr  --shared


  

./configure --omit=NetSSL_OpenSSL,Crypto,Data/ODBC,Data/MySQL --no-tests --no-samples --shared

./configure --omit=NetSSL_OpenSSL,Crypto,Data/ODBC,Data/MySQL  --shared

默认为 shared ,--static 编译静态库. --no-tests --no-samples  是不生成工程中的测试工程 和示例工程 刚了解最好生成,不过等待时间比较长.

make

照着官网的说明编译poco时,会出错.

http://pocoproject.org/docs/00200-GettingStarted.html

Building On Unix/Linux/Mac OS X

可能出现的错误:

1,错误,cmake_minimum_required(VERSION 3.0.0)

cmake 最小版本需要3.0.0以上.

2,错误make[2]: *** No rule to make target `lib/libPocoFoundation.so.1 (2014-12-22).6 (2014-12-22).0 (2014-12-22)', needed by `lib/libPocoXML.so.30'. Stop.
make[1]: *** [XML/CMakeFiles/XML.dir/all] Error 2
make: *** [all] Error 2

poco/version 文件

1.6.0 (2014-12-22)->有空格 ,,,生成 的so 文件最后有问题,不能调用.

改为

1.6.0

否则生成 so的名字中有空格,,,不能正确的生成 文件.

3.fatal error: openssl/crypto.h: No such file or directory

openssl 缺的是头文件

apt-get install libssl-dev

安装 libssl-dev解决.或 openssl-devel

生成poco   so库

在poco中执行

cmake .

make

就会看见:

[ 34%] Built target Foundation
[ 47%] Built target XML
[ 49%] Built target JSON
[ 68%] Built target Net
[ 72%] Built target MongoDB
[ 77%] Built target Util
[ 79%] Built target Crypto
[ 84%] Built target NetSSL
[ 91%] Built target Data
[ 92%] Built target DataSQLite
[ 94%] Built target DataMySQL
[ 99%] Built target Zip
[100%] Built target PageCompiler
[100%] Built target File2Page

有没有发现什么不对...

对少了debug的so文件...

所以还是不要用cmake来生成.用make 一次生成debug ,和release 这个是poco 脚本做的事.

当然cmake 也可生成 debug ,release版本.

后一篇文件:"使用GDB 追踪依赖poco的so程序,core dump文件分析"  里面有介绍.

这个网址在 下面...

为什么需要debug版本的so文件.后面调试程序会方便 很多.

后一篇文件:"使用GDB 追踪依赖poco的so程序,core dump文件分析"

http://www.cnblogs.com/bleachli/p/4704534.html

会有介绍.

如果

  CMake设置arm-linux-gcc交叉编译器

参考以下:

http://blog.sina.com.cn/s/blog_627bb2cf0101ge3r.html

so路径配置

linux找不到动态链接库 .so文件的解决方法:http://www.cnblogs.com/xudong-bupt/p/3698294.html

linux So链接路径设置:http://blog.csdn.net/a19860903/article/details/12943959

使用poco库

这就是我们所需要的东西.

那怎么使用呢.

上次提到过

关于 Poco::TCPServer框架 (windows 下使用的是 select模型) 学习笔记.

http://www.cnblogs.com/bleachli/p/4352959.html

TimeServer.cpp 的工程在

...\poco-1.6.0-all\Net\samples\TimeServer 中

看下TimeServer 目录下,自带的CMakeLists.txt

关于cmake 的学习,http://blog.csdn.net/dbzhang800/article/details/6314073

set(SAMPLE_NAME "TimeServer")

set(LOCAL_SRCS "")
aux_source_directory(src LOCAL_SRCS) add_executable( ${SAMPLE_NAME} ${LOCAL_SRCS} )
target_link_libraries( ${SAMPLE_NAME} PocoNet PocoUtil PocoJSON PocoXML PocoFoundation )

但这个不能编译,会报,少了include 头文件,以及找不到so文件.

错误信息:

[root@localhost TimeServer]# /home/cmake-3.1.3-Linux-i386/bin/cmake  .
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as cmake_minimum_required(VERSION 3.1) should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it. -- Configuring done
-- Generating done
-- Build files have been written to: /home/poco-1.6.0-all/Net/samples/TimeServer
[root@localhost TimeServer]# make
Scanning dependencies of target TimeServer
[100%] Building CXX object CMakeFiles/TimeServer.dir/src/TimeServer.o
/home/poco-1.6.0-all/Net/samples/TimeServer/src/TimeServer.cpp:15:32: fatal error: Poco/Net/TCPServer.h: No such file or directory
compilation terminated.
make[2]: *** [CMakeFiles/TimeServer.dir/src/TimeServer.o] Error 1
make[1]: *** [CMakeFiles/TimeServer.dir/all] Error 2
make: *** [all] Error 2
[root@localhost TimeServer]#

所以改改.

#定义最低版本.
cmake_minimum_required(VERSION 3.0.0) #
set(SAMPLE_NAME "TimeServer") PROJECT(${SAMPLE_NAME}) #定义工程名称 SET(CMAKE_BUILE_TYPE DEBUG) #指定编译类型 设置编译类型debug 或者release。 debug 版会生成相关调试信息,可以使用GDB 进行 #SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")

 #SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")


#ADD_SUBDIRECTORY(utility) #添加要编译的子目录 为工程主目录下的存放源代码的子目录使用该命令,各子目录出现的顺序随意。
#
set(path_root_dir "/home/poco-1.6.0-all") # 添加头文件搜索路径
include_directories(${path_root_dir}/Net/include)
include_directories(${path_root_dir}/Util/include)
include_directories(${path_root_dir}/JSON/include)
include_directories(${path_root_dir}/XML/include)
include_directories(${path_root_dir}/Foundation/include)
#include_directories(${path_root_dir}lib/) # 添加非标准的共享库搜索路径
LINK_DIRECTORIES(${path_root_dir}/lib/) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${path_root_dir}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${path_root_dir}/lib)
# Windows DLLs are "runtime" for CMake. Output them to "bin" like the Visual Studio projects do.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${path_root_dir}/bin)
#设置程序exe输出位置
#SET(EXECUTABLE_OUTPUT_PATH ${path_root_dir}/bin) MESSAGE(STATUS "t1 This is SOURCE dir ${path_root_dir}/Net")
MESSAGE(STATUS "t1 This is SOURCE dir ${path_root_dir}/bin") #
set(LOCAL_SRCS "") # aux_source_directory 作用是发现一个目录下所有的源代码文件并将列表存储在一个变量中,这个指令临时被用来
# 自动构建源文件列表。因为目前cmake还不能自动发现新添加的源文件。
aux_source_directory(src LOCAL_SRCS) # 生成exe 名字为 ${SAMPLE_NAME} 的值
add_executable(${SAMPLE_NAME} ${LOCAL_SRCS} )
# 这个指令可以用来为target添加需要链接的共享库
target_link_libraries( ${SAMPLE_NAME} PocoNet PocoUtil PocoJSON PocoXML PocoFoundation )

再运行:

[root@localhost TimeServer]# /home/cmake-3.1.3-Linux-i386/bin/cmake  .
-- t1 This is SOURCE dir /home/poco-1.6.0-all/Net
-- t1 This is SOURCE dir /home/poco-1.6.0-all/bin
-- Configuring done
-- Generating done
-- Build files have been written to: /home/poco-1.6.0-all/Net/samples/TimeServer
[root@localhost TimeServer]# make
-- t1 This is SOURCE dir /home/poco-1.6.0-all/Net
-- t1 This is SOURCE dir /home/poco-1.6.0-all/bin
-- Configuring done
-- Generating done
-- Build files have been written to: /home/poco-1.6.0-all/Net/samples/TimeServer
[100%] Built target TimeServer
[root@localhost TimeServer]# ^C
[root@localhost TimeServer]#

生成 TimeServer程序.

 

[root@localhost ~]# netstat  -nlap | grep Time
tcp 0 0 0.0.0.0:9911 0.0.0.0:* LISTEN 29518/./TimeServer

用gdb 调试 TimeServer

  关于调试,网上说的很多不能调试.

  gdb使用可参考:

  http://blog.csdn.net/bobocheng1231/article/details/2513741

[root@localhost bin]# gdb TimeServer
GNU gdb (GDB) Fedora (7.5.0.20120926-25.fc18)
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/poco-1.6.0-all/bin/TimeServer...(no debugging symbols found)...done.
(gdb) info b
No breakpoints or watchpoints.
#设置断点
(gdb) b TimeServerConnection::run
Breakpoint 1 at 0x804be43
#运行
(gdb) r
Starting program: /home/poco-1.6.0-all/bin/TimeServer
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".
[New Thread 0xb7babb40 (LWP 17365)]
[New Thread 0xb73aab40 (LWP 17366)]
[New Thread 0xb6ba9b40 (LWP 17367)]
[Switching to Thread 0xb7babb40 (LWP 17365)]
Breakpoint 1, 0x0804be43 in TimeServerConnection::run() ()
Missing separate debuginfos, use: debuginfo-install glibc-2.16-24.fc18.i686 libgcc-4.7.2-8.fc18.i686 libstdc++-4.7.2-8.fc18.i686
#显示 信息
(gdb) l
1 <built-in>: No such file or directory.
(gdb) l
1 in <built-in>
(gdb)

结果 不能显示 出信息.

纠结许久.google之解决 问题.

原文:

http://www.cmake.org/pipermail/cmake/2012-September/052071.html

Stupid, stupid me. Yes it works, I just ran GDB with "start" instead of
"run".
Thanks for your help Nils. Chris On 2012/09/19 04:56 PM, Nils Gladitz wrote:
> "cmake -DCMAKE_BUILD_TYPE=Debug" should be enough to get gdb
> debuggable binaries.
> Is the process which you intend to debug running when you ask gdb for
> a backtrace?
> You will only be able to get a backtrace if the process has been
> started and has not yet exited.
>
> e.g.:
> gdb ./mybin
> break main
> run
> backtrace
>
> Nils
>
> On 09/19/2012 04:43 PM, GOO Creations wrote:
>> Hi,
>>
>> I'm trying to debug my program using GDB. I've done the following:
>>
>> -DCMAKE_BUILD_TYPE=Debug
>> SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -g")
>> SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
>>
>> But whenever I run GDB and do a backtrace, I get a message: "No Stack".
>> I've done a Google search and apparently the -g flag is never passed
>> to g++.
>> Is -g automatically added when my build type is "Debug"? Does anyone
>> know why GDB gives me this error?
>>
>> Thanks
>> Chris
>> --
>>
>> Powered by www.kitware.com

使用start 代替run 命令.

于试再试试

[root@localhost bin]# gdb TimeServer
GNU gdb (GDB) Fedora (7.5.0.20120926-25.fc18)
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/poco-1.6.0-all/bin/TimeServer...(no debugging symbols found)...done.
#设置断点
(gdb) b TimeServerConnection::run
Breakpoint 1 at 0x804be43
#断点信息
(gdb) info b
Num Type Disp Enb Address What
1 breakpoint keep y 0x0804be43 <TimeServerConnection::run()+5>
#查看源码
(gdb) l
No symbol table is loaded. Use the "file" command.
#开始
(gdb) start
Temporary breakpoint 2 at 0x804b924
Starting program: /home/poco-1.6.0-all/bin/TimeServer
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1". Temporary breakpoint 2, 0x0804b924 in main ()
Missing separate debuginfos, use: debuginfo-install glibc-2.16-24.fc18.i686 libgcc-4.7.2-8.fc18.i686 libstdc++-4.7.2-8.fc18.i686
(gdb) l
1 //
2 // TextConverter.cpp
3 //
4 // $Id: //poco/1.4/Foundation/src/TextConverter.cpp#1 $
5 //
6 // Library: Foundation
7 // Package: Text
8 // Module: TextConverter
9 //
10 // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
(gdb) c
Continuing.
[New Thread 0xb7babb40 (LWP 17405)]
[New Thread 0xb73aab40 (LWP 17406)]
[New Thread 0xb6ba9b40 (LWP 17407)]
[Switching to Thread 0xb7babb40 (LWP 17405)] Breakpoint 1, 0x0804be43 in TimeServerConnection::run() ()
#源码信息.....
(gdb) l
11 // and Contributors.
12 //
13 // SPDX-License-Identifier: BSL-1.0
14 //
15
16
17 #include "Poco/TextConverter.h"
18 #include "Poco/TextIterator.h"
19 #include "Poco/TextEncoding.h"
20
(gdb) n
Single stepping until exit from function _ZN20TimeServerConnection3runEv,
which has no line number information.
Request from 192.168.10.220:13986
Poco::Net::TCPServerConnection::start (this=0xb6000468)
at /home/poco-1.6.0-all/Net/src/TCPServerConnection.cpp:59
59 }
(gdb) l
54 }
55 catch (...)
56 {
57 ErrorHandler::handle();
58 }
59 }
60
61
62 } } // namespace Poco::Net
(gdb) n
Poco::Net::TCPServerDispatcher::run (this=0x8066308)
at /home/poco-1.6.0-all/Net/src/TCPServerDispatcher.cpp:117
117 endConnection();
(gdb) l
112 {
113 std::auto_ptr<TCPServerConnection> pConnection(_pConnectionFactory->createConnection(pCNf->socket()));
114 poco_check_ptr(pConnection.get());
115 beginConnection();
116 pConnection->start();
117 endConnection();
118 }
119 }
120
121 FastMutex::ScopedLock lock(_mutex);
(gdb) n
121 FastMutex::ScopedLock lock(_mutex);
(gdb) n
122 if (_stopped || (_currentThreads > 1 && _queue.empty()))
(gdb) l
117 endConnection();
118 }
119 }
120
121 FastMutex::ScopedLock lock(_mutex);
122 if (_stopped || (_currentThreads > 1 && _queue.empty()))
123 {
124 --_currentThreads;
125 break;
126 }
(gdb) c
Continuing. Breakpoint 1, 0x0804be43 in TimeServerConnection::run() ()
(gdb)

这样就可以调试了.

文章中如有错误,欢迎朋友们指点,谢谢.

linux 下cmake 编译 ,调用,调试 poco 1.6.0 小记的更多相关文章

  1. linux下cmake编译安装、配置和卸载mysql

    WIN10下虚拟机:VMware workstation 12 PRO 安装 # 1.查看系统版本 [root@vm-xiluhua][/home/xiluhua]$ cat /etc/redhat- ...

  2. LINUX下文件编译

    body, table{font-family: 微软雅黑} table{border-collapse: collapse; border: solid gray; border-width: 2p ...

  3. [转] linux下的c/c++调试器gdb

    PS:1. 断点C++类函数,用b 命名空间::类名::方法名 2. 编译参数一定要加-g,才可断点调试 http://www.cnblogs.com/xd502djj/archive/2012/08 ...

  4. FFmpeg在Linux下安装编译过程

    转载请把头部出处链接和尾部二维码一起转载,本文出自:http://blog.csdn.net/hejjunlin/article/details/52402759 今天介绍下FFmpeg在Linux下 ...

  5. linux下的c/c++调试器gdb

    Reference:  http://www.cnblogs.com/xd502djj/archive/2012/08/30/2663960.html linux下的c/c++调试器gdb gdbLi ...

  6. 从四个问题透析Linux下C++编译&链接

    摘要:编译&链接对C&C++程序员既熟悉又陌生,熟悉在于每份代码都要经历编译&链接过程,陌生在于大部分人并不会刻意关注编译&链接的原理.本文通过开发过程中碰到的四个典型 ...

  7. 在linux下sh批处理文件调用java的方法

    解密 java -classpath collection-impl-0.0.1.jar com.ai.toptea.collection.message.DESEncrypt 1EFE4663895 ...

  8. Linux下nginx编译安装教程和编译参数详解

    这篇文章主要介绍了Linux下nginx编译安装教程和编译参数详解,需要的朋友可以参考下 一.必要软件准备1.安装pcre 为了支持rewrite功能,我们需要安装pcre 复制代码代码如下: # y ...

  9. linux下c程序调用reboot函数实现直接重启【转】

    转自:http://www.blog.chinaunix.net/uid-20564848-id-73878.html linux下c程序调用reboot函数实现直接重启 当然你也可以直接调用syst ...

随机推荐

  1. ThinkPhp 验证码不显示图片

    验证码不显示原因分析: 1.先确保是否开启了 gd库 2.页面是否存在bom头 3.导入的ORG.Util.Image是否存在 4.入口文件中是否有define('APP_DEBUG', TRUE); ...

  2. [NHibernate]Nullables

    系列文章 [Nhibernate]体系结构 [NHibernate]ISessionFactory配置 [NHibernate]持久化类(Persistent Classes) [NHibernate ...

  3. ASP.NET WEB API路由机制

    (一)路由原理 (二)路由设计架构分析 RouteBase

  4. 入门: 使用JNI 从C++代码中调用Java的静态方法

    开发环境: 操作系统: (uname -a output)  Linux ubuntu 3.8.0-19-generic #29-Ubuntu SMP Wed Apr 17 18:16:28 UTC ...

  5. Excel 实用技巧之一

    1.在单元格内换行: Alt+Enter 2.合并其他单元格文字并换行: A1&char(10)&B1 3.Excel计算样本估算总体方差:STDEV/STDEVA(),分母为n-1. ...

  6. C# 使用Silverlight toolkit Chart

    一.基础介绍 Silverlight ToolKit是微软发布的基于Microsoft-Public License(MS-PL)许可协议的控件集.MS-PL许可协议允许商业或非商业的发布,所以我们可 ...

  7. CSS样式自动换行(强制换行)与强制不换行

    自动换行问题,正常字符的换行是比较合理的,而连续的数字和英文字符常常将容器撑大,挺让人头疼,下面介绍的是CSS如何实现换行的方法 对于div,p等块级元素,正常文字的换行(亚洲文字和非亚洲文字)元素拥 ...

  8. HTTP API开发

    近期手上的安卓app需要用到自动更新的功能,想着怎么实现,看了下很多应用商店的sdk,觉得不太好,可能会收集用户隐私,于是想着自己实现一个http api后面自己可以实现自动更新,甚至广告推送的功能, ...

  9. C和指针 第十一章 习题

    1编写calloc,内部使用malloc函数获取内存 #include <stdio.h> #include <stdlib.h> void *myAlloc(unsigned ...

  10. 02第一个OC程序

    一.打开XCode4.6.3,新建项目 二.选择Application下的命名行项目 三.输入项目名称,选择Foundation框架创建项目,点击Next 四.二话不说.点击Run.启动我们创建的项目 ...