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)

这样就可以调试了.

 

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

 

posted @ 2015-03-25 20:29  bleach3  阅读(6976)  评论(0编辑  收藏  举报