linux 下cmake 编译 ,调用,调试 poco 1.6.0 小记
上篇文章 小记了:
关于 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 小记的更多相关文章
- linux下cmake编译安装、配置和卸载mysql
WIN10下虚拟机:VMware workstation 12 PRO 安装 # 1.查看系统版本 [root@vm-xiluhua][/home/xiluhua]$ cat /etc/redhat- ...
- LINUX下文件编译
body, table{font-family: 微软雅黑} table{border-collapse: collapse; border: solid gray; border-width: 2p ...
- [转] linux下的c/c++调试器gdb
PS:1. 断点C++类函数,用b 命名空间::类名::方法名 2. 编译参数一定要加-g,才可断点调试 http://www.cnblogs.com/xd502djj/archive/2012/08 ...
- FFmpeg在Linux下安装编译过程
转载请把头部出处链接和尾部二维码一起转载,本文出自:http://blog.csdn.net/hejjunlin/article/details/52402759 今天介绍下FFmpeg在Linux下 ...
- linux下的c/c++调试器gdb
Reference: http://www.cnblogs.com/xd502djj/archive/2012/08/30/2663960.html linux下的c/c++调试器gdb gdbLi ...
- 从四个问题透析Linux下C++编译&链接
摘要:编译&链接对C&C++程序员既熟悉又陌生,熟悉在于每份代码都要经历编译&链接过程,陌生在于大部分人并不会刻意关注编译&链接的原理.本文通过开发过程中碰到的四个典型 ...
- 在linux下sh批处理文件调用java的方法
解密 java -classpath collection-impl-0.0.1.jar com.ai.toptea.collection.message.DESEncrypt 1EFE4663895 ...
- Linux下nginx编译安装教程和编译参数详解
这篇文章主要介绍了Linux下nginx编译安装教程和编译参数详解,需要的朋友可以参考下 一.必要软件准备1.安装pcre 为了支持rewrite功能,我们需要安装pcre 复制代码代码如下: # y ...
- linux下c程序调用reboot函数实现直接重启【转】
转自:http://www.blog.chinaunix.net/uid-20564848-id-73878.html linux下c程序调用reboot函数实现直接重启 当然你也可以直接调用syst ...
随机推荐
- 学习笔记——k近邻法
对新的输入实例,在训练数据集中找到与该实例最邻近的\(k\)个实例,这\(k\)个实例的多数属于某个类,就把该输入实例分给这个类. \(k\) 近邻法(\(k\)-nearest neighbor, ...
- IBatis 2.x 和 MyBatis 3.0.x 的区别(从 iBatis 到 MyBatis)
从 iBatis 到 MyBatis,你准备好了吗? 对于从事 Java EE 的开发人员来说,iBatis 是一个再熟悉不过的持久层框架了,在 Hibernate.JPA 这样的一站式对象 / 关系 ...
- JUnit4 中@AfterClass @BeforeClass @after @before的区别对比
JUnit4使用Java5中的注解(annotation),以下是JUnit4常用的几个annotation: @Before:初始化方法 对于每一个测试方法都要执行一次(注意与BeforeCla ...
- Spring3.0目录
(1)Spring 入门知识 (2)IoC/DI基本思想的演变 (3)深入理解IoC/DI (4)Spring的简单demo
- 【转载】借助GitHub托管你的项目代码
PS:自己关注博客园有2年之久了,不久前才申请注册账号.GitHub也差不多一年多了,因英语水平刚刚及格,所以去GitHub没有博客园多,也是几个月前才注册了账号,前几天休息时看到 EdisonCho ...
- C# 读取excel日期时获取到数字转换成日期
string strDate= DateTime.FromOADate(Convert.ToInt32(data[i][7])).ToString("d"); strDate= D ...
- vue2.0学习(一)
1.解决双花括号在初始化时的闪烁,两种方式,一种是<div v-text="name"></div>,将用v-text指令来显示,类似于angular的ng ...
- coding.net就这么横空出世
各位新生们好: 看罢以上的开场白博客,我们也算初步完成了一个小程序——hello world.再进一步想下去,若我们程序写大了,要不停修改了(1000行代码不长,只争朝夕:-D),该如何保存呢?保存到 ...
- mingw32 捕获异常的4种方法
------------------------------------------------------------------------------- 1. 利用 windows 的API S ...
- Odoo9是如何计算预定交付日期的
计算预定日期目的是按计划交付.接收等.根据不同公司习惯,Odoo会通过调度器自动生成预定日期,Odoo调度器计算每一行的每件事情,无论是生产订单.交货单.销售订单等,依据Odoo中配置的不同交付时间( ...